# Multiple NodeRed Instances on different Ports - Linux/SystemD

**URL:** https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555
**Category:** General
**Created:** [28 March 2019 18:24 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555 "2019-03-28T18:24:01Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Dustin](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Dustin](https://discourse.nodered.org/u/Dustin)
#### Post date: [28 March 2019 18:24 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/1 "2019-03-28T18:24:01Z")

</div>

I know this has been addressed because I've made it work in the past, so I apologize for rehashing an already discussed topic... but I can't seem to find the instructions again. I've tried multiple times using some of the other methods I've found to get this to work and have done nothing but break Node\_Red repeatedly.

I have an AWS server and I need to run 2 instances of NodeRed on 2 different ports. I'm running Ubuntu and using SystemD to autostart Node-Red on boot.

The goal is to have 2 admin panels so that 2 different people can test and develop without having to boot up a second server with its own Node-Red install... and be able to point 2 different domains to the UI of those instances.

I'd like to avoid using PM2 if possible, as I used this method of autostart when I installed: [https://nodered.org/docs/hardware/raspberrypi#adding-autostart-capability-using-systemd](https://nodered.org/docs/hardware/raspberrypi#adding-autostart-capability-using-systemd)

I tried the following instructions, but only managed to get an error saying it can't find red.js and Node-Red failed to boot: [https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-2/](https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-2/)

So I've rolled back... fresh install of Node-Red... What's the easiest way to get 2 instances running on 2 different ports?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![tilleul](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tilleul/32/78_2.png) [@tilleul](https://discourse.nodered.org/u/tilleul)
#### Post date: [28 March 2019 19:11 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/2 "2019-03-28T19:11:55Z")

</div>

What I do, is create two different directories and do `npm i node-red` in each one and then edit the `settings.js` file in `node_modules/node-red` so that they use different ports.

And then, in each directory, I launch two node-reds using a command like `node node_modules/node-red/red -s node_modules/node-red/settings.js -u ./`

This tells node-red to use the `settings.js` file found in the `node_modules/node-red` directory and to create a `flow.json` file in the current directory.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [28 March 2019 20:59 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/3 "2019-03-28T20:59:34Z")

</div>

Use the command line options.

### Command-line usage

```auto
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

```

You only need to install once then run a second, third, nth instance with different command line options.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [28 March 2019 21:02 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/4 "2019-03-28T21:02:38Z")

</div>

Typically I do ...

```auto
node-red -u /node-red-1881 -p 1881

```

Just noticed the -p option is missing from documentation (but it definitely works)

Perhaps documentation is out of date?

[https://nodered.org/docs/getting-started/running](https://nodered.org/docs/getting-started/running)

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [28 March 2019 21:20 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/6 "2019-03-28T21:20:59Z")

</div>

Hi @Steve-Mcl, good point. The part to be updated is the result of the node-red --help, which would be:

![doc-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/29913d7980a5ef37d7a7e9e3afb20b8ea76bcd22.png)

I will fork the doc repository and try to submit a pull request.

---

<div class="post-metadata">

### Author: ![Dustin](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Dustin](https://discourse.nodered.org/u/Dustin)
#### Post date: [28 March 2019 21:53 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/7 "2019-03-28T21:53:38Z")

</div>

Thanks for the reply. I've seen several posts regarding the CLI options...

I just can't seem to get those incorporated into the auto-startup option. I may not have been very clear in my post, sorry.

I am using systemd to auto-start the node-red service. Currently it starts 1 instance on port 1880.

I need it to also auto-start a second instance on port 1881.

I've tried copying the /lib/systemd/system/nodered.service, renaming it, modifying the internal settings to try and pull from different settings.js files... and then modifying those settings.js files to use different ports.

I've tried modifying the Environment line to include the options you've specified for the CLI.... but no matter what I try, it either tries to start a second instance on the same port, or throws some other error...like can't find "red.js".

Am I over-complicating this by trying to use SystemD to autostart both... and maybe I should just write a script?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [28 March 2019 22:13 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/8 "2019-03-28T22:13:33Z")

</div>

Show us your modified systemd script that tries to specify the settings and flow file.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [28 March 2019 22:49 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/9 "2019-03-28T22:49:03Z")

</div>

> [@Dustin](#):
>
> I need it to also auto-start a second instance on port 1881

As long as your settings.js file is right, you can do this via an environment variable. I posted my setup a few days ago that showed how to do this via an environment file.

## settings.js:

```
uiPort: process.env.PORT || 1880,

```

## /etc/systemd/system/multi-user.target.wants/nrlive.service

Obviously you can call this whatever you want.

```auto
# See https://gist.github.com/Belphemur/3f6d3bf211b0e8a18d93
# http://www.freedesktop.org/wiki/Software/systemd/
#
# If changing this file, run:
# sudo systemctl daemon-reload && sudo systemctl enable nrlive

[Unit]
Description=Node-Red Home Automation production (live) service
Documentation=file:///home/pi/nrlive/README.md http://nodered.org/docs
After=syslog.target network.target
Wants=mosquitto.service influxdb.service

[Service]
Type=simple

#Environment="NODE_OPTIONS=--max-old-space-size=128" "NODE_RED_OPTIONS=--userDir /home/pi/nrlive/.data -v"
#Environment="NODE_RED_OPTIONS=-v"

# Environment variables file, overrides the Environment settings
# @See https://www.freedesktop.org/software/systemd/man/systemd.exec.html#EnvironmentFile=
EnvironmentFile=/home/pi/nrlive/.data/envFile.txt

# No path available here so make sure absolute folders specified
ExecStart=/usr/bin/node $NODE_OPTIONS /home/pi/nrlive/node_modules/node-red/red.js $NODE_RED_OPTIONS

WorkingDirectory=/home/pi/nrlive

# User/Group that launches node-RED (it's advised to create a new user for Node-RED)
# You can do : sudo useradd node-red then change the User=root by User=node-red
User=pi
Group=pi

Nice=10

SyslogIdentifier=NRlive
StandardOutput=syslog

# Make Node-RED restart if it fails
Restart=on-failure

#Restart=always
#RestartSec=100

# Node-RED need a SIGINT to be notified to stop
KillSignal=SIGINT

# Prevent this service changing the OS or /etc
# @See https://www.freedesktop.org/software/systemd/man/systemd.exec.html#ProtectSystem=
ProtectSystem=full

[Install]
WantedBy=multi-user.target

```

## envFile.txt

```auto
# Environment variables file for running nrlive under SystemD
# Each line is a separate variable that will be available to the ExecStart
# and to the running process.
# @see https://www.freedesktop.org/software/systemd/man/systemd.exec.html#EnvironmentFile=
#
# Called from /etc/systemd/system/multi-user.target.wants/nrlive.service
# Which is linked from /home/pi/nrlive/systemd/nrlive.service

NODE_OPTIONS=--max_old_space_size=256
NODE_RED_OPTIONS=--userDir /home/pi/nrlive/.data -v
PORT=1880

```

---

<div class="post-metadata">

### Author: ![Dustin](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Dustin](https://discourse.nodered.org/u/Dustin)
#### Post date: [28 March 2019 23:14 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/10 "2019-03-28T23:14:57Z")

</div>

@Colin I mentioned in my first post that I wiped everything and started fresh, so my systemd file is currently a wget from: [https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service](https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/nodered.service)

as instructed here: [https://nodered.org/docs/hardware/raspberrypi#adding-autostart-capability-using-systemd](https://nodered.org/docs/hardware/raspberrypi#adding-autostart-capability-using-systemd)

I probably should have started with my modified file and asked for help, but nothing worked, and I wasn't even sure I was on the right track really.

@TotallyInformation Thanks for the post! I am pretty sure I can get that to work. I'll try first thing when I get back in the office tomorrow morning.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [28 March 2019 23:16 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/11 "2019-03-28T23:16:57Z")

</div>

> [@Dustin](#):
>
> Thanks for the post! I am pretty sure I can get that to work. I'll try first thing when I get back in the office tomorrow morning.

No problem. Just note that I don't use the standard installation of Node-RED. Instead I prefer to install to a "master" folder with a sub-folder containing the userDir. I'm sure you will be able to adjust according to your needs.

---

<div class="post-metadata">

### Author: ![ozpos](https://avatars.discourse-cdn.com/v4/letter/o/278dde/32.png) [@ozpos](https://discourse.nodered.org/u/ozpos)
#### Post date: [9 July 2020 15:42 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/12 "2020-07-09T15:42:21Z")

</div>

When running multiple instances (each on a different port and from different folders. e.g. ~/.node-red-1888, ~/.node-red-1880 etc), can they also be of different versions say v1.1.1, 1.0.4 etc ?

I have tried-  
npm install --prefix .node-red-1880 node-red@1.0.4,  
npm install -g --prefix .node-red-1880 node-red@1.0.4

from within the target directory (~./node-red-1880) and the parent but with no effect.

Any ideas anyone ?

P.S. I gave up with customising systemd for now. Just starting NR with-  
./node-red-pi.sh

---

<div class="post-metadata">

### Author: ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)
#### Post date: [9 July 2020 17:35 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/13 "2020-07-09T17:35:20Z")

</div>

I don't know what the prefix parameter for npm does but maybe this gives you a clue:

```auto
cd ~/.node-red-1888
npm install node-red@1.0.4 # install to node_modules under current dir
npx node-red-pi -s settings.js -u . -p 1888 # run node-red-pi executable from ./node_modules/bin

```

Edit: just tested this and it should work

---

<div class="post-metadata">

### Author: ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)
#### Post date: [9 July 2020 17:54 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/14 "2020-07-09T17:54:19Z")

</div>

You can simply do local installs (without the `-g` switch) into separate directories.

I have all versions installed in an `apps` directory in my home dir. That's how I have managed it for some time now. The `node-red` symlink points to my currently preferred version.

```auto
~/apps
├── node-red -> node-red_1.0
├── node-red_0.19
│ ├── node_modules
│ └── package.json
├── node-red_0.20
│ ├── node_modules
│ └── package.json
├── node-red_1.0
│ ├── node_modules
│ ├── package.json
│ └── package-lock.json
└── node-red_1.1
    ├── node_modules
    ├── package.json
    └── package-lock.json

```

---

<div class="post-metadata">

### Author: ![ozpos](https://avatars.discourse-cdn.com/v4/letter/o/278dde/32.png) [@ozpos](https://discourse.nodered.org/u/ozpos)
#### Post date: [9 July 2020 17:56 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/15 "2020-07-09T17:56:58Z")

</div>

Thank you. What is npx ?  
Its alright I will google it.

Was it you @ristomatti that said you have seen many an old dog fall by the wayside with all this js malarky, well I am just on the edge of adding to that list.

Life is too short to spend much more time on transient stuff like this. I only came here to offer up my experience with NR and make a few suggestions.

I was pretty sure from the beginning that this task was beyond my capabilities and it is turning out that way.

Hope you all have a nice time.

---

<div class="post-metadata">

### Author: ![ozpos](https://avatars.discourse-cdn.com/v4/letter/o/278dde/32.png) [@ozpos](https://discourse.nodered.org/u/ozpos)
#### Post date: [9 July 2020 17:58 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/16 "2020-07-09T17:58:35Z")

</div>

Thank you but how are they installed in each folder

---

<div class="post-metadata">

### Author: ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)
#### Post date: [9 July 2020 18:02 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/17 "2020-07-09T18:02:15Z")

</div>

> [@ozpos](#):
>
> Thank you. What is npx ?

It's a helper utility that comes with node. The idea is that packages can define executable scripts in `package.json` that if installed globally, will be added to your `PATH`. When installing packages to local directory without the `-g / --global` flag, the executables are copied under `./node_modules/.bin`. `npx` runs the scripts from this hidden dir but it also has a more powerful feature to transparently download a node module (to npm's cache directory under your home dir) with the given name and execute it.

> **[Introducing npx: an npm package runner](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b)**
>
> \[You can also read this post in Russian.\]

Example of the transparent download and execute use case for those who are curious:

```auto
cat package.json | npx json2yaml

```

---

<div class="post-metadata">

### Author: ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)
#### Post date: [9 July 2020 18:02 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/18 "2020-07-09T18:02:17Z")

</div>

Just create the folder, say `node-red_1.1`, change into it, and execute `npm install node-red@1.1` in there.

You could do an `npm init` there first, to create a `package.json` to pin the dependencies to the desired version.

I'd generally advice against global npm installs. Gets you into more trouble than it's worth.

---

<div class="post-metadata">

### Author: ![ozpos](https://avatars.discourse-cdn.com/v4/letter/o/278dde/32.png) [@ozpos](https://discourse.nodered.org/u/ozpos)
#### Post date: [9 July 2020 18:14 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/19 "2020-07-09T18:14:01Z")

</div>

It is only in desperation that I gave it a try based on some example on the web that clearly does not work.

Do you know what is the easiest way of removing all trace of a global install under linux ?

Or should I start another topic !

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [9 July 2020 18:14 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/20 "2020-07-09T18:14:49Z")

</div>

> [@ozpos](#):
>
> Do you know what is the easiest way of removing all trace of a global install under linux ?

```auto
npm remove -g node-red

```

---

<div class="post-metadata">

### Author: ![ozpos](https://avatars.discourse-cdn.com/v4/letter/o/278dde/32.png) [@ozpos](https://discourse.nodered.org/u/ozpos)
#### Post date: [9 July 2020 19:00 UTC](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555/21 "2020-07-09T19:00:03Z")

</div>

still reports v1.1.1 and that breaks my flow. I will try and work with npx.

[Next page](https://discourse.nodered.org/t/multiple-nodered-instances-on-different-ports-linux-systemd/9555.md?page=2)
