Node-red is a flow based development tool I use at home for getting my sensor-data in an Influx-database and with a Grafana front-end expose the data. That setup runs on a Intel NUC with Ubuntu 18.04 so time to get it upgraded to 20.04. But before I upgrade I want to know I am able to run all my things on 20.04. In this post I will show the installation of node-red, some basic configuration and how to run it. You might be aware of the option to install things on Ubuntu using snap. And that will work fine, but I do not really like snap. So my installation is a bit more work, as we will need to install nodejs and npm first.
$ sudo apt-get install Node.js
This will run for a while and when done you can verify the install with the following command.
$ node -v
At the time of writing this post you should get v10.19.0
We also need npm to be installed, run the following command, it will take a while to install.
$ sudo apt-get install npm
And again you can verify the installed version ($ npm -v), which at the time of writing this post was 6.14.4. Now we are ready to install node-red using npm. We will install it with the -g option and thus install it a global module with all the needed dependencies.
$ sudo npm install -g --unsafe-perm node-red
If all went well you should se something like as the final command output.
COPY Release/bcrypt_lib.node COPY /usr/local/lib/node_modules/node-red/node_modules/bcrypt/lib/binding/bcrypt_lib.node TOUCH Release/obj.target/action_after_build.stamp make: Leaving directory '/usr/local/lib/node_modules/node-red/node_modules/bcrypt/build' + firstname.lastname@example.org added 330 packages from 339 contributors in 88.32s
You can now start it in the home directory of the user of your own choice. When started it will create a hidden folder .node-red. There node-red will store the settings for the node-red instance from that user. Start node-red with the following command and wait until you see the node-red server is up and running. In the past (Raspberry Pi 3) there was limited memory available on the Pi and there is the option the start node-red with an additional argument, this argument would tell Node.js to release unused memory sooner. The newer Raspberry Pi’s can be purchased with up to 4 GB of RAM on those this might not be needed anymore, but will also do no harm. When you node-red keeps crashing unexpected you definitely want to add the argument.
Staring node-red on Raspberry Pi's without the extra argument $ node-red Starting node-red with the extra memory argument $ node-red-pi --max-old-space-size=256
Now open your favorite browser and go to the IP of your Raspberry Pi and port 1880. In my case: 192.168.2.190:1880 and you should see the design page for node-red.
As I want to run have node-red running after I close my ssh connection, I just run it using nohup. It is also possible to run node-red as a service which will automatically start after a reboot. But that’s for a future post. If you still have node-red running, kill it using “ctrl-c” and execute the following command. I do not echo the output to /dev/null so I will see a nohup.out file showing up in the directory you run the command. If you do not want the nohup.out file on your system just pipe your output to /dev/null or some other file. It might be a good idea to think about this anyway, because this file will keep growing if you do not clean or remove it. And if you have limited space on your SD-card you might not want this file to grow unlimited.
When you do not care and are happy with a nohup.out file created $ nohup node-red & When you want to check what is happening but you want to control the filename $ nohup node-red > my-log-file & When you do not want to see any files $ nohup node-red >& /dev/null & Remember to use the node-red-pi command if you have a Raspberry Pi with limited memory.
That’s it, node-red is installed and will keep running unless you reboot your Raspberry Pi. In next posts we will have start to create some flows and add some extra components to node-red.