Node-Red on Ubuntu VPS or Raspberry Pi4

Table of Contents

    1. Installation on VPS running Ubuntu

    1. Install NPM
      sudo apt install npm -y
    2. Install Node-RED as a global module along with all its dependencies
      sudo npm install -g --unsafe-perm node-red
    3. Open default port 1880 on firewall
      sudo ufw allow 1880
    4. Start Node-Red
      node-red start
    5. Wait a few seconds while service starts and then go to: http://YOUR-IP-Address:1880
      The Node-Red dashboard should load

    2. Autostart Node-RED on Boot.

    1. Create a new systemd file for the nodered.service
      sudo nano /etc/systemd/system/nodered.service
    2. add the following (change yourUser to your username):
    ExecStart=/usr/local/bin/node-red --max-old-space-size=128 -v
    # log output to syslog as 'node-red'
    # non-root user to run as
    # if using a root user
    1. Enable the Node-RED service and run this file on boot
      sudo systemctl enable nodered.service
    2. Restart to test if Node-RED is automatically starts on boot
      sudo reboot

    NOTE! The previous steps did not work when I installed on Raspberry Pi.

    I need to verify the following steps when installing on Raspberry Pi.

    It did not start automatically on bootup and the authentication module did not load
    To load in the background on bootup I did this:

    pm2 start /usr/bin/node-red –node-args=”–max-old-space-size=128″ — -v
    on VPS you use this: pm2 start /usr/bin/node-red — -v

    You can view information about the process and access the log output using the commands:
    pm2 info node-red
    pm2 logs node-red

    ** Tell PM2 to run on boot**
    pm2 startup systemd

    3. Secure Node-RED Software with Username and Password

    1. Install node-red-admin package to make it available globally:
      sudo npm install -g --unsafe-perm node-red-admin
    2. create a password hash
      node-red-admin hash-pw
    3. You will be prompted for a password. Type your desired password, press Enter key, and a hash will be printed on screen
    4. Copy the hash string to your clipboard and open the Node-RED settings file
      sudo nano ~/.node-red/settings.js
    5. Scroll down and uncomment the adminAuth block (by removing the “// ” in front of each line). Change username to whatever you like, and paste the previously generated hash into the password field.