How to run Node-RED on the Raspberry Pi

necessary conditions

If you are using Raspberry Pi OS, Buster is the currently supported version.

install

Install and upgrade Node-RED

We provide a script to install Node.js, npm, and Node-RED on a Raspberry Pi. This script can also be used to upgrade existing installations when a new version is available.

Running the following command will download and run the script. If you want to see the contents of the script first, you can view it on Github.

bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

You can pass additional parameters to the script. Add –help to the above command to see them.

This script works on any Debian-based operating system, including Ubuntu and Diet-Pi. You may want to run sudo apt install build-essential git curl first to ensure that npm can fetch and build any binary modules it needs to install.

This script will:

· Remove the existing version of Node-RED if it exists.

· If it detects that Node.js is installed, it will ensure that it is at least v12. If below v12, it will stop and let users decide whether to continue using Node-RED version 1 – or upgrade Nodejs to a newer LTS version. If not found, it will use the NodeSource package to install the current Node.js LTS version.

· Use npm to install the latest version of Node-RED.

· Optionally install a useful set of Pi-specific nodes.

· Set up Node-RED to run as a service and provide a set of commands to use the service.

Node-RED also packages the Raspberry Pi OS repository and appears on their “Recommended Software” list. This allows it to be installed using apt-get install nodered and includes the Raspberry Pi OS packaged version of Node.js, but not npm.

Note: At this time, the default node.js included with RaspiOS Bullseye is still v12. This means that the latest Node-RED version that can be installed is the 2.x branch. While these packages are convenient to use initially, we strongly recommend using the installation script above instead.

run locally

Just like running Node-RED locally, you can run Node-RED in the terminal using the node-red command. It can then be stopped by pressing Ctrl-C or closing the terminal window.

Since the Raspberry Pi has limited memory, you need to start Node-RED with additional parameters to tell the underlying Node.js process to release unused memory faster than it would otherwise.

To do this, you should use the alternative node-red-pi command and pass in the max-old-space-size parameter.

node-red-pi –max-old-space-size=256

Run as a service

The Pi’s installation script also sets it up to run as a service. This means it can run in the background and be enabled to start automatically on boot.

The following commands are provided to use the service:

node-red-start – This will start the Node-RED service and display its log output.Pressing Ctrl-C or closing the window does not stop the service; it keeps running in the background

node-red-stop – This will stop the Node-RED service

node-red-restart – This will stop and restart the Node-RED service

node-red-log – This will display the log output of the service

You can also start the Node-RED service on the Raspberry Pi OS desktop by selecting the Menu -> Programming -> Node-RED menu option.

Start automatically at boot

If you want Node-RED to run when the Pi is turned on or rebooted, you can have the service start automatically by running the following command:

sudo systemctl enable nodered.service

To disable the service, run the following command:

sudo systemctl disable nodered.service

Open editor

After Node-RED is running, you can access the editor in your browser.

If you are using a browser on the Pi desktop, you can open the address: http://localhost:1880.

We recommend using a browser outside the IP and pointing it to Node-RED running on the Pi. But you can use the built-in browser, if so we recommend Chromium or Firefox-ESR instead of Epiphany

When browsing from another machine, you should use the Pi’s hostname or IP address http:// :1880. You can find the IP address by running hostname -I on the Pi.

X

Contact us

Contact us