# How to use the new Group environment variables feature

**URL:** <https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259>\
**Category:** General\
**Created:** [16 December 2021 03:43 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259 "2021-12-16T03:43:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikefatom](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@mikefatom](https://discourse.nodered.org/u/mikefatom)\
**Post date:** [16 December 2021 03:43 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259/1 "2021-12-16T03:43:27Z")

</div>

Hello,  
I'm new here so please excuse the noob question. 🙂

How does one access environment variables defined at a Group level in a function node?

I tried using `let myVar = env.get("MY_ENV_VAR");`

but all i get is `undefined`.

Any help is appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [16 December 2021 04:52 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259/2 "2021-12-16T04:52:27Z")

</div>

That should work, can you post a copy of your flow ?

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [16 December 2021 04:54 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259/3 "2021-12-16T04:54:11Z")

</div>

Also, what version of Node-RED are you running ?  
I believe there was a bug related to this in a recent version.

---

<div class="post-metadata">

**Author:** ![mikefatom](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@mikefatom](https://discourse.nodered.org/u/mikefatom)\
**Post date:** [16 December 2021 05:59 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259/4 "2021-12-16T05:59:36Z")

</div>

Hi nlecaude!

I'm using version 2.1.4 (latest).

Here is a sample flow:

```auto
[{"id":"5f365e1f0d126a64","type":"tab","label":"Group ENV var Example","disabled":false,"info":"","env":[]},{"id":"49320e1a34d79d7a","type":"group","z":"5f365e1f0d126a64","name":"","style":{"label":true},"nodes":["e4ce71cac84a8b42","03b51c21aca00702","c4b0ca9442f89ef4"],"env":[{"name":"MY_ENV_VAR","value":"hello","type":"str"}],"x":114,"y":79,"w":692,"h":82},{"id":"e4ce71cac84a8b42","type":"inject","z":"5f365e1f0d126a64","g":"49320e1a34d79d7a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":220,"y":120,"wires":[["03b51c21aca00702"]]},{"id":"03b51c21aca00702","type":"function","z":"5f365e1f0d126a64","g":"49320e1a34d79d7a","name":"Get MY_ENV_VAR","func":"let myVal = env.get(\"MY_ENV_VAR\");\n\nmsg.payload = myVal;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":120,"wires":[["c4b0ca9442f89ef4"]]},{"id":"c4b0ca9442f89ef4","type":"debug","z":"5f365e1f0d126a64","g":"49320e1a34d79d7a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":120,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [16 December 2021 06:17 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259/5 "2021-12-16T06:17:41Z")

</div>

I just tested this and it seems to be a bug.  
If I set it at the tab level it works…  
I suggest you fill an issue with your example flow on github.

---

<div class="post-metadata">

**Author:** ![mikefatom](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@mikefatom](https://discourse.nodered.org/u/mikefatom)\
**Post date:** [16 December 2021 16:21 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259/6 "2021-12-16T16:21:23Z")

</div>

Done!

[https://github.com/node-red/node-red/issues/3299](https://github.com/node-red/node-red/issues/3299)

---

<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:** [14 February 2022 16:22 UTC](https://discourse.nodered.org/t/how-to-use-the-new-group-environment-variables-feature/55259/7 "2022-02-14T16:22:15Z")

</div>

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