How to use the new Group environment variables feature

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

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!

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

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

Hi nlecaude!

I'm using version 2.1.4 (latest).

Here is a sample flow:

[{"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":[]}]

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.

Done!

https://github.com/node-red/node-red/issues/3299

1 Like