# Configure env variables

**URL:** <https://discourse.nodered.org/t/configure-env-variables/96345>\
**Category:** General\
**Created:** [31 March 2025 01:24 UTC](https://discourse.nodered.org/t/configure-env-variables/96345 "2025-03-31T01:24:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigbean17](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigbean17/32/89814_2.png) [@bigbean17](https://discourse.nodered.org/u/bigbean17)\
**Post date:** [31 March 2025 01:24 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/1 "2025-03-31T01:24:36Z")

</div>

Hi,

In my application, the users are allowed to configure env vars of the application, such as TIMEZONE. Currently, what I did is to rewrite the whole settings.js file to change the variable. This works but is there a better way of doing this instead of rewriting the settings.js?

Thank you!

---

<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:** [31 March 2025 07:34 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/2 "2025-03-31T07:34:53Z")

</div>

This is quite loaded and not enough info for me to give any real direction

Can you explain how you have allowed users (via what interface/what process) can your users change env vars?

Also, on your particular example of users changing TIMEZONE, I am uncertain why you would permit a user (client) to modify the backend (server) timezone. (There is likely a better pattern here)

In what way have you rewritten the whole settings.js file?

Are your users allowed to access the node-red editor? Do they have deploy permissions?

---

<div class="post-metadata">

**Author:** ![bigbean17](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bigbean17/32/89814_2.png) [@bigbean17](https://discourse.nodered.org/u/bigbean17)\
**Post date:** [31 March 2025 20:17 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/3 "2025-03-31T20:17:43Z")

</div>

Hi,

I have a simple web interface that accepts users' input of the env variables. One user could have multiple devices located at different locations, so they are allowed to change the serial number and timezone etc. which are defined in the settings.js.

Users are not allowed to touch the settings.js directly, but only through that form. When a user submit the form, the backend code will import settings.js, overwrite the process.env.xx and write them into settings.js using fs.

Users are not allowed to access the node-red editor, the backend will re-deploy node-red if the env vars are saved successfully.

Hope that could clarify. Thanks

---

<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:** [2 April 2025 07:58 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/4 "2025-04-02T07:58:16Z")

</div>

Assuming that node-red is running under linux [Edit: and using systemd] then if you add a line to the node-red startup script defining the environment variable EnvironmentFile pointing to a file, for example  
`EnvironmentFile=/home/nodereduser/environment`  
then node-red will pick up env vars from there. Using that method would mean that you only need to write to that file and restart node-red, rather than modifiying settings.js

[Edit: In fact the standard systemd startup script already includes a similar line, which you can adjust if necessary to specify where you want the file]

If you are running under Windows then you could modify settings.js to read in the environment file directly rather than using the startup script.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 April 2025 08:15 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/5 "2025-04-02T08:15:12Z")

</div>

> [@Colin](#):
>
> add a line to the node-red startup script defining the environment variable EnvironmentFile  
> ... for example  
> `EnvironmentFile=/home/nodereduser/environment`

The installer script for Debian already adds this line to the systemd script `/lib/systemd/system/nodered.service`, so if you start node-red with `sudo systemctl [start|enable] nodered` or by `node-red-start` environment variables declared in that file be available in Node-red.

However, starting Node-red with `node-red` at the command line does not use the systemd script and the variables **are not expressed within Node-red**.

---

<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:** [2 April 2025 08:30 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/6 "2025-04-02T08:30:20Z")

</div>

> [@jbudd](#):
>
> The installer script for Debian already adds this line to the systemd script

It isn't quite that line, but similar.

> [@jbudd](#):
>
> However, starting Node-red with `node-red` at the command line does not use the systemd script and the variables **are not expressed within Node-red**.

I believe that if the EnvironmentFile env var is defined then node red will use that whether it is started with systemd or not, though I have not tested that.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 April 2025 08:46 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/7 "2025-04-02T08:46:21Z")

</div>

> [@Colin](#):
>
> It isn't quite that line, but similar.

You are right.  
Currently the script adds this line (for username pi)  
`EnvironmentFile=-/home/pi/.node-red/environment` but if the server has had Node-red on it for a long time the file may instead contain  
`EnvironmentFile=-/home/pi/.node-red/environmentFile` (I think)

Don't know the significance of the hyphen at the start!

> [@Colin](#):
>
> I have not tested that.

I just tried; it didn't, though I may have mistyped something.

```auto
 ls -l $EnvironmentFile
-rw-r--r-- 1 pi pi 84 Mar 31 02:38 /home/pi/.node-red/environment

```

ps I think I once suggested that any environment variable file processed at startup should be logged just as the settings file and context store are.

---

<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:** [2 April 2025 09:01 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/8 "2025-04-02T09:01:16Z")

</div>

> [@jbudd](#):
>
> > [@Colin](#):
> >
> > I have not tested that.
> 
> I just tried; it didn't

Thanks for testing that. I have corrected my original post accordingly.

---

<div class="post-metadata">

**Author:** ![ThingsTinkerer](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@ThingsTinkerer](https://discourse.nodered.org/u/ThingsTinkerer)\
**Post date:** [3 April 2025 11:52 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/9 "2025-04-03T11:52:10Z")

</div>

This works surprisingly well with docker, by adding arg `--env-file .env` to docker run command. Unfortunately I found no similar equivalent when running container in azure with `az container create`.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 July 2025 11:52 UTC](https://discourse.nodered.org/t/configure-env-variables/96345/10 "2025-07-02T11:52:36Z")

</div>

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