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):
    [Unit]
    Description=Node-RED
    After=syslog.target network.target
    
    [Service]
    ExecStart=/usr/local/bin/node-red --max-old-space-size=128 -v
    Restart=on-failure
    KillSignal=SIGINT
    
    # log output to syslog as 'node-red'
    SyslogIdentifier=node-red
    StandardOutput=syslog
    
    # non-root user to run as
    WorkingDirectory=/home/yourUser/
    User=yourUser
    Group=yourUser
    
    # if using a root user
    #WorkingDirectory=/root/
    #User=root
    #Group=root
    
    [Install]
    WantedBy=multi-user.target
    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.
    https://nodered.org/docs/faq/starting-node-red-on-boot

    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
    copy

    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.