There are many methods of starting, stopping and monitoring applications at boot time. This guide highlights some of the possible ways of doing it.
The Raspberry Pi install script we provide can be used on any Debian-like operating system.
This script installs Node-RED as a systemd service. For more information, read the Running on Raspberry Pi guide.
If you are not using Raspberry Pi OS, you may need to edit the service file to suit your local user id and environment. Details for how to do that are available here.
We also provide an install script for RPM based linux available here, that also sets up systemd.
The guide below sets out what we believe to be the most straight-forward for the majority of users. For Windows, PM2 does not autorun as a service - you may prefer the NSSM option below.
PM2 is a process manager for Node.js. It makes it easy to run applications on boot and ensure they are restarted if necessary.
sudo npm install -g pm2
sudo
is required if running as a non-root user on Linux or OS X. If
running on Windows, you will need to run in a command shell as Administrator,
without the sudo
command.
tail.exe
is on your path, as
described here.
node-red
command.If you have done a global install of node-red, then on Linux/OS X the node-red
command will probably be either: /usr/bin/node-red
or /usr/local/bin/node-red
.
The command which node-red
can be used to confirm the location.
If you have done a local install, it will be node_modules/node-red/bin/node-red
,
relative to where you ran npm install
from.
The following command tells PM2 to run Node-RED, assuming /usr/bin/node-red
as
the location of the node-red
command.
The --
argument must appear before any arguments you want to pass to node-red.
pm2 start /usr/bin/node-red -- -v
pm2 start /usr/bin/node-red --node-args="--max-old-space-size=128" -- -v
This will start Node-RED in the background. You can view information about the process and access the log output using the commands:
pm2 info node-red
pm2 logs node-red
More information about managing processes under PM2 is available here.
PM2 is able to generate and configure a startup script suitable for the platform it is being run on.
Run these commands and follow the instructions it provides:
pm2 save
pm2 startup
for newer Linux systems that use systemd use
pm2 startup systemd
export PM2_HOME="/root/.pm2"to point at the correct directory, which would be like:
export PM2_HOME="/home/{youruser}/.pm2"
Finally, reboot and check everything starts as expected.
PM2 does not autorun as a service on Windows. An alternative option is to use NSSM, an example of which is available from the community link below.
There are many alternative approaches. The following are some of those created by members of the community.
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy