# \[Proposal\] Global Environment Variable

**URL:** <https://discourse.nodered.org/t/proposal-global-environment-variable/65560>\
**Category:** Core Development\
**Created:** [25 July 2022 07:34 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560 "2022-07-25T07:34:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nisiyama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nisiyama/32/85_2.png) [@nisiyama](https://discourse.nodered.org/u/nisiyama)\
**Post date:** [25 July 2022 07:34 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/1 "2022-07-25T07:34:13Z")

</div>

The current Node-Red allows environment variables to be defined for Subflow, Group, and Tab.  
However, in some cases, we may want to specify environment variables that are effective for multiple tabs and settings of configuration nodes that do not belong to a tab.

**[Proposal]**  
To solve the above problem, I would like to propose adding a feature to define global environment variables to the **User Settings** panel of Node-RED editor as shown in the following figure.

 ![スクリーンショット 2022-07-25 15.56.41](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8e38dd68eea9a7f74d621f7a88aba5ab4c2ee1ce.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2022 08:09 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/2 "2022-07-25T08:09:51Z")

</div>

what would happen if you also set ABC\_USER outside of Node-RED ? Which would have precedence ?

---

<div class="post-metadata">

**Author:** ![nisiyama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nisiyama/32/85_2.png) [@nisiyama](https://discourse.nodered.org/u/nisiyama)\
**Post date:** [25 July 2022 08:12 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/3 "2022-07-25T08:12:33Z")

</div>

It will be referenced before accessing OS environment variable.  
So, the precedence is as follows:

1. SUBFLOW/Group
2. Tab
3. Global
4. OS

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2022 08:23 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/4 "2022-07-25T08:23:01Z")

</div>

Other app use a .env file - should these global variables be stored in a .env file that could also be edited outside of Node-RED (but displayed/edited as per above) - so it could be part of a deployment workflow - or should they just be part of the flow.

(I'm trying to think when / who / how they should be used... at a global level to me it seems more of a deployment level environment - so I may want to set them at deploy time.... though if you set them just internally with the precedence as above then indeed they would be "locked" to the values set - which may also be useful occasionally)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [25 July 2022 08:52 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/5 "2022-07-25T08:52:28Z")

</div>

Where would they get stored?

If you want them to be set via the editor, then it has to be via the storage API. The storage API gives two options - either part of the flows or part of the runtime settings.

They cannot be part of the flow.json (as we have no way of storing top-level properties like this). That means they won't be included when the flow is exported from the editor - unlike flow/group env vars.

The 'User Settings' dialog is specific to the user - with values stored in the runtime settings file against that username. But these settings wouldn't be per-user - they are, as you say global. We don't have anything like that currently.

---

<div class="post-metadata">

**Author:** ![nisiyama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nisiyama/32/85_2.png) [@nisiyama](https://discourse.nodered.org/u/nisiyama)\
**Post date:** [25 July 2022 09:11 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/6 "2022-07-25T09:11:38Z")

</div>

In my current assumption, global environment variables are saved as part of runtime settings file, possibly `.config.runtime.json` or `.config.users.json`.  
Another possibility is use of new special config node that holds the global variable mappings.

I think it is possible to use `.env` file instead, but there is a problem that the value of the environment variable is limited to a simple string type.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [25 July 2022 09:23 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/7 "2022-07-25T09:23:27Z")

</div>

If they need to be typed then I think they may need a different name... when I think of environment variables then they should always just be simple strings. (and I would vote for them to be held in a .env file - but I can see this would cause issues on systems where you may not have a file system)

---

<div class="post-metadata">

**Author:** ![nisiyama](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nisiyama/32/85_2.png) [@nisiyama](https://discourse.nodered.org/u/nisiyama)\
**Post date:** [25 July 2022 09:30 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/8 "2022-07-25T09:30:59Z")

</div>

Yes. I agree that the name is a confusing.  
But, it is currently named as _Environment Variable_ in both OS and Node-RED.

---

<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 September 2022 09:31 UTC](https://discourse.nodered.org/t/proposal-global-environment-variable/65560/9 "2022-09-23T09:31:24Z")

</div>

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