How to Perfectly AutoStart Node-Red on Raspberry Pi Boot up
Posted February 20, 2024
Are you working on Raspberry Pi OS? This guide teaches you how to Perfectly AutoStart Node-Red on Raspberry Pi during Boot up.
Step 1: Installing Node-Red on Raspberry Pi
Create an SSH connection and run the following command to install Node-Red on your Raspberry OS:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
If you want more details on Node-Red installation check How to Install and Run Node-Red on Raspberry Pi
Step 2: AutoStart Node-Red on Raspberry Pi with PM2
PM2 (Process Manager 2) is a popular process manager for Node.js. Node-Red runs on top of Node.js. This means Raspberry will be able to use PM2 and create an AutoStart set up to automatically restart Node-Red on boot up.
PM2 will generate startup scripts for Node-Red and Raspberry based on the following steps:
- Install PM2 globally:
sudo npm install -g pm2
npm install -g pm2
- Start Node-RED using PM2 to start enabling Node-RED Raspberry AutoStart:
pm2 start `which node-red` -- -v
On this command, you can use --max-old-space-size=128
to reduce Node-Red memory usage on Raspberry Pi devices with limited resources:
pm2 start `which node-red` -- --max-old-space-size=128
- To AutoStart Node-RED, Raspberry will use PM2 to save Node-RED to the PM2 process list:
pm2 save
- Next, use PM2 Startup Script to enable Node-RED Raspberry AutoStart:
pm2 startup
Note: Copy your above Start Up script and run it
- Finally, use either of the following commands to verify if Node-RED is running and managed by PM2. AutoStart will only work if you have Node-RED as a list running PM2 processes:
pm2 list
pm2 monit
- To disable PM2 from managing Node-RED AutoStart, use the following commands:
# Stop Node-RED
pm2 stop node-red
# Restart
pm2 restart node-red
# Remove
pm2 delete node-red
Step 3: AutoStart Node-Red using Raspberry Systemctl
Instead of using PM2, you can as well Raspberry Pi use Systemctl and add Node-RED AutoStart. Node-RED will start automatically when your Raspberry Pi boots up as follows:
- Enable Node-Red service to AutoStart:
sudo systemctl enable nodered.service
- If you no longer want Raspberry to AutoStart Node-RED, disable the service using the following command:
sudo systemctl disable nodered.service
Conclusion
This guide taught you how to Perfectly AutoStart Node-Red on Raspberry Pi during Boot up. You successfully installed and run Node-RED on your Raspberry Pi. Now start building your flows and automations using Node-RED.