# How to keep env variables in a project?

**URL:** <https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715>\
**Category:** General\
**Created:** [24 July 2024 01:02 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715 "2024-07-24T01:02:20Z")\
**Posts on this page:** 7\
**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:** [24 July 2024 01:02 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715/1 "2024-07-24T01:02:20Z")

</div>

Hi,

In my project, each device has several unique properties such as serial\_number and owner\_id. Every time I setup a new device for my customer, I need to manually set the env vars for the flow by double clicking the flow tab and put the key-value pairs in.

I have a development machine which will push changes and all the devices will only pull from the repo. However, every time I pull the code, the env vars will be overwritten, I have to manually set the vars for each single device.

It has a very bad scalability if there are thousands of devices, it is impossible to manually setup the env vars every time I need to update the code.

What would be the best practice of this?

Thank for helping!

---

<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:** [24 July 2024 06:44 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715/2 "2024-07-24T06:44:27Z")

</div>

That depends on the OS and how you run node red.

---

<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:** [24 July 2024 07:00 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715/3 "2024-07-24T07:00:55Z")

</div>

It runs on Ubuntu 20.04, there is a service for node-red named `run_node_red` to run node-red.

---

<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:** [24 July 2024 07:10 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715/4 "2024-07-24T07:10:50Z")

</div>

The Linux Node-red installer supplies a systemd script which can set up environment variables. But you seem to be using some other startup mechanism.

You can specify environment variables in settings.js. it's not difficult to write a script to do this.

---

<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:** [24 July 2024 08:50 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715/5 "2024-07-24T08:50:31Z")

</div>

In the systemd script you can include a file containing env vars, which you could modify for each system. As @jbudd says the pi/debian/ubuntu install script does this for you. The systemd script includes the line  
`EnvironmentFile=-/home/colinl/.node-red/environment`  
so you could do something similar in your script. The `-` before the path tells systemd not to error out if the file does not exist.

---

<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:** [25 July 2024 06:27 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715/6 "2024-07-25T06:27:27Z")

</div>

I will give a try, thanks for helping! @jbudd @Colin

---

<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:** [23 October 2024 06:27 UTC](https://discourse.nodered.org/t/how-to-keep-env-variables-in-a-project/89715/7 "2024-10-23T06:27:40Z")

</div>

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