Error in user guide?

The user guide on using environment variables says that when Node-red is running as a service, environment variables can be defined in a file ~/.node-red/environment.

The file path seems to be defined in /lib/systemd/system/nodered.service:

# define an optional environment file in Node-RED's user directory to set custom variables externally
EnvironmentFile=-/home/pi/.node-red/EnvironmentFile

I find that variables defined in ~/.nodered/environment are not set, but those defined in ~/.nodered/EnvironmentFile are.
The documentation needs a change to reflect this.

Hmm - actually it's a bug in the install script that is setting that incorrectly...

Hmm indeed. For backwards compatibility it'll have to be changed now to process either file?

Does the same process for setting environment variables work on Windows? Which file?

it will work with whatever file you configure in the nodered.service file.
The default nodered.service file sets it to 'environment' (as per the docs) - but the install script "updates" it to EnvironmentFile
I don't think it would work on Windows as that doesn't use the service file to set up the environment.

It would be harsh to "fix" only the install script. Anyone who has looked at nodered.service and uses .node-red/EnvironmentFile installs the next release of Node-red and their environment variables stop working.

On the other hand, anyone who has read the documentation and found .node-red/environment doesn't work has probably already found another solution.

Do you know if @TotallyInformation's (?) "alternative installation" sets up nodered.service too?

Not unless you are using WSL2 to run systemd and Node-RED.

To get something cross-platform, use env - npm in settings.js.

I do know. :slight_smile:

My install has an example systemd script that you can use but it doesn't install it automatically. That is up to you. There are instructions on how to do it and how/where to set an env file.

Indeed, my example settings.js file also has far more env controllable settings than the default.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.