| layout | docs |
|---|---|
| toc | getting-started-toc.html |
| title | Running |
If you have installed Node-RED as a global npm package, you can use the node-red
command:
$ node-red
Welcome to Node-RED
===================
25 Mar 22:51:09 - [info] Node-RED version: v0.18.4
25 Mar 22:51:09 - [info] Node.js version: v8.11.1
25 Mar 22:51:09 - [info] Loading palette nodes
25 Mar 22:51:10 - [warn] ------------------------------------------
25 Mar 22:51:10 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
25 Mar 22:51:10 - [warn] ------------------------------------------
25 Mar 22:51:10 - [info] Settings file : /home/nol/.node-red/settings.js
25 Mar 22:51:10 - [info] User Directory : /home/nol/.node-red
25 Mar 22:51:10 - [info] Server now running at http://127.0.0.1:1880/
25 Mar 22:51:10 - [info] Creating new flows file : flows_noltop.json
25 Mar 22:51:10 - [info] Starting flows
25 Mar 22:51:10 - [info] Started flows
You can then access the Node-RED editor by pointing your browser at http://localhost:1880.
There are specific instructions available for certain hardware platforms:
You can now create your first flow.
Usage: node-red [-v] [-?] [--settings settings.js] [--userDir DIR] [flows.json]
Options:
-s, --settings FILE use specified settings file
-u, --userDir DIR use specified user directory
-v enable verbose output
-?, --help show usage
The node-red command can still be accessed even if Node-RED hasn't been installed
as a global npm package.
If you have npm installed Node-RED, this script will be node_modules/node-red/bin/node-red,
relative to the directory you ran npm install in. If you have installed from a
release zip file, the script will be node-red-X.Y.Z/bin/node-red, relative to
the directory you extracted the zip into.
First make the node-red start script executable:
chmod +x <node-red-install-directory>/bin/node-red
Then you can start Node-RED with:
<node-red-install-directory>/bin/node-red
On Windows, run the following command from the same directory you ran npm install
in, or that you extracted the release zip file:
node node_modules/node-red/red.js
By default, Node-RED stores your data in the directory $HOME/.node-red. For
backwards compatibility reasons, if Node-RED detects user data in its install
directory, it will use that instead. The upgrading documentation
includes a section on migrating your data out of the Node-RED install directory.
To override what directory to use, the --userDir command-line option can be used.
There are occasions when it is necessary to pass arguments to the underlying Node.js process. For example, when running on devices like the Raspberry Pi or BeagleBone Black that have a constrained amount of memory.
To do this, you must use the node-red-pi start script in place of node-red.
Note: this script is not available on Windows.
Alternatively, if are running Node-RED using the node command, you must provide
arguments for the node process before specifying red.js and the arguments you
want passed to Node-RED itself.
The following two commands show these two approaches:
node-red-pi --max-old-space-size=128 --userDir /home/user/node-red-data/
node --max-old-space-size=128 red.js --userDir /home/user/node-red-data/
There are many methods of starting, stopping and monitoring applications at boot time. Raspberry Pi users are strongly recommended to follow these instructions.
Linux users that have a Debian flavour (e.g. Ubuntu, Mint, Debian, etc) are recommended to use the
Adding Autostart capability using SystemD
instructions from the Raspberry Pi docs though you will need to edit the downloaded /lib/systemd/system/nodered.service file to suit your user id and environment.
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.
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.
There are many alternative approaches. The following are some of those created by members of the community.
- A systemd script (used by the Pi pre-install) by @NodeRED (linux)
- A systemd script by Belphemur (linux)
- An init.d script by dceejay (linux)
- An init.d script by Belphemur (linux)
- A Launchd script by natcl (OS X)
- Running as a Windows service using NSSM by dceejay
- Running as Windows/OS X service by Ben Hardill