Node-RED is a digital flowchart tool for connecting different online services and devices. It helps you easily create automation and data-handling processes without needing to write a lot of code, you can use the web interface to design even very complex flows for automation control.
Prerequisites
You need to install the required packages.
- curl
- bash
You can find the instructions here.
Installation of Node-RED
First, update the repositories.
sudo apt-get update
Enter below command to start node-red installation process:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
If any error encounters During the installation process, i.e. "user is not in sudoer group", either give sudo privileges' to normal user or you can try to run whole process as root, but that can be done only on specific requirements.
Installing is not suggested to done as root user, this kind of typical installation is only performed under normal user, not at all as root user
it will ask for various questions while installation startup, all of them are answered with a "Y", But enter "N" when it asks for 'Raspberry PI spec node'.
As shown below go through warnings and exec "sudo chown root:root ~/.node-red/settings.js" as suggested.
At the end, the installer will ask if we want to secure the instance. Hence it is necessary secure it, enter the username and password for the Node-RED panel as per convenience. (Ref image below)
For sack of avoiding any hurdles go with basic/default settings, But must apply password.
Remember to make your password long and complicated enough. The security of your gateway depends on it.
After installation, you need to execute below command :
sudo node-red-pi --max-old-space-size=256
Node-RED will start and will be available on port "localhost:1880".
Open in any browser of host system connected to same IP range or in same networking area.
It will prompt for "username/password", feed with the same credentials configured back while installation process.
Node-RED AutoStart
In the last step node-red was started after manual command executed in CLI,
In order to automatically start node-red on gateway startup, it needs to be entered into the startup system. To do so, execute below commands:
sudo npm install pm2@latest -g
If ask to " run `npm fund` for details", do the same and process for next command:
sudo pm2 start /usr/bin/node-red --node-args="--max-old-space-size=256" -- -v
You will get below output after command executed, check for user in table, if not "root", need to change user to "root" from normal user.
If user is "root" proceed to below command or else skip this step.
pm2 save
pm2 startup
For changing user from "normal user" to "root" for node-red startup, follow below steps:
sudo pm2 start node-red -u root
sudo pm2 save
If any warning shown on screen use "--force" flag, i.e. "sudo pm2 save --force"
Must check the symlink created should have service "pm2-root.service"
sudo pm2 startup
sudo pm2 save
Reboot the device, for cross checking and verifying proper installation.
once rebooted, check below command:
ps -aux | grep pm2
Check either it's daemon running over root or not, if not you might have misguided somewhere and make mistake while installation, please refer again and install.
Open "localhost:1880" and start node-red.