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.
# 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