In this tutorial, we will learn how to install Node-RED on a Raspberry Pi. This installation process will make Node-RED work on both 32-bit and 64-bit versions of the Raspian operating system.
Before you proceed with this tutorial, you should have a Raspberry Pi setup with a Raspian image installed on it. If not, you can check this guide:
Buy raspberry pi here: Buy here
Steps to Install Node-RED on Raspberry Pi
Before starting with the installation process you should access your Rpi with an SSH connection or through a VNC viewer.
SSH into Raspberry Pi
We need an application such as putty to establish an SSH connection with Raspberry Pi. We will be using Putty in this tutorial. We will use Putty for Windows. It is a free-to-download SSH client.
Download Putty from this link and install it on your Windows based system.
After downloading and installing Putty. Now type “Putty” in the Windows search bar and run it as an administrator.
After you have downloaded it successfully, open Putty. Enter raspberrypi.local as the hostname and leave the port to 22 (default). Now press Open.
If you are using Linux or Mac, you can SSH into Raspberry Pi by using the following command:
ssh pi@raspberrypi.local
Now enter the username and password of Raspberry Pi that we previously set. By default the username is ‘pi’ and the password is ‘raspberry.’ But we have set the password to different in the above steps using raspberry pi imager.
Node-RED Installation Command for Raspberry Pi
After establishing an SSH connection with your board, run the following the command on Raspberry Pi terminal to install Node-RED:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
The above command will update the required packages and upgrade the Node-RED to the latest version. Because Node-RED comes by default in a 32-bit version of Raspberry Pi OS. But in the 64-bit version, this command will install Node-RED if it is not installed by default and update the packages to the recent versions.
When you run this command on Raspberry pi, it will ask you for your consent to install this with this message shown below. Enter Y and it will start the installation process.
After that, you may be asked: “Would you like to install Pi-specific nodes?” Write Y and press Enter.
The following image shows that the installation is in progress. It will take some time depending on your internet connection speed.
After installation is complete, you will get this message on the Raspberry Pi terminal.
Raspberry Pi Configure Node-RED Settings
After the installation process is completed, it is time to configure Node-RED to set initial options and settings. Run the following command on the Raspberry Pi terminal:
node-red admin init
After running the above command, complete the following steps:
- First, hit Enter, it will create a Node-RED settings file on /home/pi/.node-red/settings.js
- Do you want to set up user security? Yes.
- Enter a username and press Enter (you need to remember it later).
- Enter a password and press Enter (you need to remember it later).
- Next option is to define user permissions. We will provide full access to Node-Red. Press Enter to set full access.
- This option can create different users and give different permissions to different users. But for now, we will add only one. But if you need you can add more user later on.
- Do you want to enable the Projects feature? No.
- Enter a name for your flows file. Press Enter to select the default name flows.json.
- Provide a passphrase to encrypt your credentials file. Learn more about what is a passphrase.
- Select a theme for the editor. Simply press Enter to select default.
- Press Enter again to select the default text editor.
- Allow Function nodes to load external modules? Yes.
It will configure and set the settings of Node-RED and it will be stored in /home/pi/.node-red/settings.js.
Start Node-RED on Raspberry Pi
After setting configuration in settings.js, run the following command to start Node-RED on Raspberry Pi:
node-red-start
If it is started successfully, you will get the following messages on the Rpi terminal:
Access Node-RED
To access Node-RED, we need the IP address of your Raspberry Pi and the port number on which Node-RED is accessible. By default, it starts on port 1880.
To access Node-RED, open any web browser and enter the RPI IP address followed by the port number.
192.168.18.8:1880
You will get access to the Node-RED login page with your username and password as shown below. You can log in by using the username and password which we created in the configuration setting section of this tutorial.
After signing in, you will have access to the Node-RED. You can start creating projects with flows.
Raspberry Pi Autostart Node-RED on boot up
There are two ways to start an application on boot in Linux. One is using init.d and the second one is using systems services. The systemd service is the most recent one and most commonly used these days. RPI OS is based on the Linux kernel. Hence, we Node-RED provides a systemd service to start it on boot up.
To automatically start Node-RED when the Raspberry Pi powers up, enter the following command on the terminal, it will enable systemd service for node-red.
sudo systemctl enable nodered.service
Now with the above command enabled, as long as your Raspberry Pi is up and running, Node-RED will be also running.
To test if the above command is working, restart your RPI and you will see that Node-RED will be already running.
sudo reboot
If you want to disable autostart for any reason on boot, you can run the following command:
sudo systemctl disable nodered.service
In summary, in this tutorial, we have learned to install, configure, access, and start Node-Red on Raspberry Pi.
You may also like to read: