This is a guide for a secure installation of Node-Red on Raspberry Pi 4 running Ubuntu Server 21.10.
Node-RED is a low-code programming environment for event-driven applications. It uses flow-based programming to let you draw a visual representation of how messages should flow through the application. Developers can quickly create meaningful applications without having to write a lot of code. Node-Red is one of my favorite applications for prototyping IoT and Blockchain applications.
This guide is written for installation on Raspberry Pi however setup would be nearly identical on a VPS. I have several Node-Red instances running on the lowest tier of Digital Ocean droplets.
1. Install Ubuntu Server 21.10.
2. Install build tools required by NPM
sudo apt install build-essential git curl
3. Install Node-Red and Required Dependencies
Node-red.org provides this script to install Node.js, npm and Node-RED onto a Raspberry Pi. The script can also be used to upgrade an existing install when a new release is available. I have found that installation via this script to be the most user friendly way to manage the installation. This will ensure Node version 14 is installed. Install from User login (not root).
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) --node14
The installation script will ask the following questions:
- Do you want to install pi specific nodes. These are useful if you plan on interacting with gpio or serial ports on the pi.
2. Open default port 1880 on firewall
sudo ufw allow 1880
3. Run Node-Red Setup Script
Node-Red V2 includes a setup script to help generate a settings file which is much more convenient to get a secure setup configured.
node-red admin init
The script will ask a series of questions.
- Accept default location of setttings.js file: Example:
- Setup User Security(replace with your username,password):
- User permissions: full access
- Add another user: no
- Do you want to enable the projects feature: no
- Enter a name for you flows file(use default): flows.json
- Provice a passphrase to encrypt your credentials file: enter a passphrase
- Select editor theme
- Select text editor(use default)
- Allow Function Nodes to load external modules?: Yes
4. Autostart Node-Red on Boot
Use the following to enable the Node-Red to autostart after boot.
sudo systemctl enable nodered.service
sudo reboot now
5. Test that everything is working
Wait a minute after rebooting and you should be able to access the editor by going to:
http://ip address of pi:1880
It will ask for your username and login configured during the setup script.
6. Node-Red Commands
The following commands are provided to work with the Node-Red service
node-red-start – Starts the Node-RED service and displays its log output.
node-red-stop – Stops the Node-RED service
node-red-restart – Stops and restarts the Node-RED service
node-red-log – Displays the log output of the service