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.
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.
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?
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.
# 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
# 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
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.
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
I don't know what the prefix parameter for npm does but maybe this gives you a clue:
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
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.
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.
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.
Example of the transparent download and execute use case for those who are curious: