Written by Marek Černocký, Wednesday 24 April 2019
An official way how to build and install a node is using npm command. However it is not possible to find it on our routers as router is embedded device with limited resources and some nodes require complex building environment and high performance because of other languages than JavaScript.
Fortunately, it is easy to prepare a node on PC with Linux and then copy it to the router. You can meet two kinds of nodes: written in JavaScript only and written in JavaScript and other language(s).
Note: Some node authors provide prebuilt binaries so you can install this one easily as JavaScript only nodes. Look for message:
WARN install No prebuilt binaries found
in npm output. Such node is second mentioned kind.
This nodes need NPM package manager only. Install NPM via your distribution repository. For example:
apt-get install npm
for deb based distributions or:
dnf install npm (or yum install npm)
for rpm based distributions.
Now you can prepare desired node:
npm --global-style install NODE
where NODE is a node name as you can find it on www.npmjs.org.
Once it is finished you can see node_modules folder with desired node folder inside. Copy the node folder to the router via FTP/SFTP. Preferred target folder is /usr/lib/node_modules/node-red/nodes for Node-RED nodes and /usr/lib/node_modules for other nodes. It is a good idea to place files to /opt folder and create a link from the mentioned folders to avoid overriding while upgrading a firmware.
Some nodes has parts written in other languages than JavaScript. In addition, these nodes require GYP meta-build system and a build environment relevant to the language.
GYP package is NPM dependent on most distributions so you don't need to install it separately.
For most common languages C/C++, you can use same toolchains we use for building the router user modules. See Environment setup chapter in Developing User Modules Guideline to learn how to install it.
When you have installed all prerequisites, invoke following commands:
export CC="/opt/toolchain/gcc-conel-armv7-linux-gnueabi/bin/armv7-linux-gnueabi-gcc"
export CXX="/opt/toolchain/gcc-conel-armv7-linux-gnueabi/bin/armv7-linux-gnueabi-g++"
npm --arch=arm --global-style install NODE
and continue with copying as described above.