Multiple instances of node-red using PM2?


I run node-red with pm2 using :-

pm2 start node-red

which works fine.

I can manually start a second instance with its own settings file from the command line :-

node-red -s node-red2/settings.js -u node-red2 &

and this works fine . . .

Any ideas how I can manage the second instance through pm2 aswell, so it autostarts etc. ?

I've tried

pm2 start node-red --name "node-red2" --node-args="-s node-red2/settings.js -u node-red2"

which errored trying to start node-red2 and also had the interesting side effect of killing the initial node-red instance :wink:

any ideas appreciated,

Hi Gav,

The first thing I would try is setting the port number on the pm2 call ... i.e. -p. If the two instances of node-red are fighting for the same port that might be the problem.

You will need to create a process file with your 2 instances, see

Create PM2 ecosystem file like this:

pm2 ecosystem simple

PM2 will generate ecosystem.config.js

In ecosystem.config.js will add new node-red session with argument file like this:

module.exports = {
apps : [{
name : "node20000",
script : "/usr/local/bin/node-red",
args :"-s /usr/local/lib/node_modules/node-red/settings_greci.js"

where name: is new seesion name,
script is path to node-red app,
args is path to node-red second instance config file, in my case "settings_greci.js".

I will list changes in settings_greci.js bellow:

I used port 20000 for new instance:

uiPort: process.env.PORT || 20000,

and new flow file:
flowFile: 'flows_greci.json',
After this reload pm2 ecosystems : pm2 reload /home/adichici/ecosystem.config.js