# How to using environment variables in the subflow

**URL:** <https://discourse.nodered.org/t/how-to-using-environment-variables-in-the-subflow/28773>\
**Category:** General\
**Created:** [23 June 2020 04:02 UTC](https://discourse.nodered.org/t/how-to-using-environment-variables-in-the-subflow/28773 "2020-06-23T04:02:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinyistudio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jinyistudio/32/23670_2.png) [@jinyistudio](https://discourse.nodered.org/u/jinyistudio)\
**Post date:** [23 June 2020 04:02 UTC](https://discourse.nodered.org/t/how-to-using-environment-variables-in-the-subflow/28773/1 "2020-06-23T04:02:59Z")

</div>

Hi  
I add a environment variables in the subflow. name is PinNumber and type is string. I have a Function node in this subflow. How to access PinNumber in the Function node ? 😂

`[{"id":"f89b2c94.be924","type":"func-exec","z":"aa6c467e.7329e","name":"cat gdix","func":"//var Pn = env.get(\"PinNumber\");\nvar exec = child_process.exec('cat /dev/gdi1', (error, stdout, stderr) => { \n if (error) { \n console.error(`exec error: {error}`); \n return; \n } \n //console.log(`stdout: {stdout}`); \n //console.log(`stderr: ${stderr}`); \n msg.payload = stdout.split('\\n').join('');\n callback(msg);\n}); ","outputs":1,"noerr":0,"x":382,"y":112,"wires":[[]]}]`

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [23 June 2020 04:37 UTC](https://discourse.nodered.org/t/how-to-using-environment-variables-in-the-subflow/28773/2 "2020-06-23T04:37:17Z")

</div>

Hello,  
Two things:

- please read this [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) and edit your code above accordingly so that other people can import it.

- secondly the right way is `var yourvar = env.get("yourvar");`. But as the environment variables in subflows are quite recent additions and the func-exec node you use hasn’t been updated in 1 1/2 years it could be that it doesn’t support it. Is there a reason you don’t use a combination of a normal function node and an exec node instead?

Johannes

---

<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:** [22 August 2020 04:37 UTC](https://discourse.nodered.org/t/how-to-using-environment-variables-in-the-subflow/28773/3 "2020-08-22T04:37:18Z")

</div>

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