# Multiple instances of node-red using PM2?

**URL:** <https://discourse.nodered.org/t/multiple-instances-of-node-red-using-pm2/4888>\
**Category:** General\
**Created:** [15 November 2018 10:03 UTC](https://discourse.nodered.org/t/multiple-instances-of-node-red-using-pm2/4888 "2018-11-15T10:03:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vtgav](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@vtgav](https://discourse.nodered.org/u/vtgav)\
**Post date:** [15 November 2018 10:03 UTC](https://discourse.nodered.org/t/multiple-instances-of-node-red-using-pm2/4888/1 "2018-11-15T10:03:50Z")

</div>

Greetings,

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 😉

any ideas appreciated,  
thx,  
Gav

---

<div class="post-metadata">

**Author:** ![dustinw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dustinw/32/3426_2.png) [@dustinw](https://discourse.nodered.org/u/dustinw)\
**Post date:** [15 November 2018 18:14 UTC](https://discourse.nodered.org/t/multiple-instances-of-node-red-using-pm2/4888/2 "2018-11-15T18:14:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [16 November 2018 02:20 UTC](https://discourse.nodered.org/t/multiple-instances-of-node-red-using-pm2/4888/3 "2018-11-16T02:20:33Z")

</div>

You will need to create a process file with your 2 instances, see [http://pm2.keymetrics.io/docs/usage/application-declaration/](http://pm2.keymetrics.io/docs/usage/application-declaration/)

---

<div class="post-metadata">

**Author:** ![adichici](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@adichici](https://discourse.nodered.org/u/adichici)\
**Post date:** [6 June 2019 07:14 UTC](https://discourse.nodered.org/t/multiple-instances-of-node-red-using-pm2/4888/4 "2019-06-06T07:14:16Z")

</div>

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
