Node-Red on Raspberry Pi4

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.

Table of Contents

    1. Install Ubuntu Server 21.10.

    See this guide for a secure basic installation of Ubuntu 21.10.

    2. Install build tools required by NPM

    sudo apt install build-essential git curl

    3. Install Node-Red and Required Dependencies 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 --node14

    The installation script will ask the following questions:

    1. 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.

    1. Accept default location of setttings.js file: Example: /home/friends/.node-red/settings.js
    2. Setup User Security(replace with your username,password):
      username: friends
      password: xxxxxxx
    3. User permissions: full access
    4. Add another user: no
    5. Do you want to enable the projects feature: no
    6. Enter a name for you flows file(use default): flows.json
    7. Provice a passphrase to encrypt your credentials file: enter a passphrase
    8. Select editor theme
    9. Select text editor(use default)
    10. 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