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' + email@example.com 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.
9 thoughts on “Raspberry Pi Ubuntu 20.04 Node-red”
That was a pretty nice description!
I’m waiting for the auto start function 🙂
You can make node-red start during boot. See https://nodered.org/docs/getting-started/raspberrypi
However it will thus run under the root-account I think (i have not tried that myself) and not a specific user. Off-course you can set that up in the boot-scripts but requires more work.
No, the recommended Ubuntu/Debian/Raspbian install script from the node red docs (that you linked to) does not run node-red as route. It runs (by default) as the user that ran the script.
As said I did not test is. So yes, might very well be the case. In my example I did not use the install scripts from the node-red documents, so somewhat different setup. As I wanted to confirm my current installed 18.04 Node-red configuration would not break when I upgrade to Ubuntu 20.04.
I believe that the best way to install node-red on an Ubuntu/Debian/Raspbian system is to use the recommended install script from the node-red docs. That will ensure that a version of nodejs compatible with the latest node-red will be installed. The latest node red will not run with the default nodejs (v10) provided with Ubuntu 20.04. https://nodered.org/docs/getting-started/raspberrypi
That does depend a bit on your use-case, but yes that will be fine in most cases. Might be a small issue if you do not want to upgrade nodejs. But thats all very specific, so in general I do agree.
You can’t run the latest node red without upgrading nodejs.
Could you correct my name in the previous post please? I mistyped it. You would think I would get it right after about 500,000 times of trying 🙂
A minor detail, in the first post you have
sudo apt-get install Node.js
that should be nodejs I think, and nowadays one should be using apt not apt-get, so I think it should be
sudo apt install nodejs
Agree, but not everybody needs/wants the latest version. Name fixed. Yes, well, my post is a bit older. Things change in. And typo needs to be nodejs (Will update it). apt-get will still work, but yes, apt is the new way of doing it.