• V
 

Starting Node-RED on boot

There are many methods of starting, stopping and monitoring applications at boot time. This guide highlights some of the possible ways of doing it.

Raspberry Pi, Debian, Ubuntu

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 Raspbian, 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.

RPM based Linux, RedHat, Fedora, CentOS

We also provide an install script for RPM based linux available here, that also sets up systemd.

Other Linux, OSX

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.

Using PM2

PM2 is a process manager for Node.js. It makes it easy to run applications on boot and ensure they are restarted if necessary.

1. Install PM2

sudo npm install -g pm2
Note : 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.
If running on Windows, you should also ensure tail.exe is on your path, as described here.

2. Determine the exact location of the 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.

3. Tell PM2 to run Node-RED

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
Note : if you are running on a device like the Raspberry Pi or BeagleBone Black that have a constrained amount of memory, you must pass an additional argument:
pm2 start /usr/bin/node-red --node-args="--max-old-space-size=128" -- -v
Note : if you want to run as the root user, you must use the `--userDir` option to specify where Node-RED should store your data.

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.

4. Tell PM2 to run on boot

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
Temporary Note: There's an open issue on PM2 on GitHub which highlights an issue that has been introduced recently. Linux users need to manually edit the generated `/etc/init.d/pm2-init.sh` file and replace
export PM2_HOME="/root/.pm2"
to point at the correct directory, which would be like:
export PM2_HOME="/home/{youruser}/.pm2"

5. Reboot

Finally, reboot and check everything starts as expected.

Windows

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.

Alternative options

There are many alternative approaches. The following are some of those created by members of the community.