# Possible bug Joining environment variables in typedInput

**URL:** <https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908>\
**Category:** Core Development\
**Created:** [10 October 2023 08:45 UTC](https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908 "2023-10-10T08:45:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jnn](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jnn](https://discourse.nodered.org/u/jnn)\
**Post date:** [10 October 2023 08:45 UTC](https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908/1 "2023-10-10T08:45:46Z")

</div>

I thought it was possible to joining env vars in subflows but I am doing something wrong here.  
I have checked out this thread: [https://discourse.nodered.org/t/using-subflow-environment-variable-to-set-mqtt-topic/15331/8](https://discourse.nodered.org/t/using-subflow-environment-variable-to-set-mqtt-topic/15331/8)  
Can anyone please have a look on my flow and tell me what I am doing wrong? Running Node-RED 3.1.0. Thanks in advance.

```auto
[{"id":"0ded66e5737053d9","type":"subflow","name":"Testing variables","info":"","category":"","in":[],"out":[],"env":[{"name":"TestVar","type":"str","value":"Hello"},{"name":"TestVarTwo","type":"env","value":"${TestVar}/there"}],"meta":{},"color":"#DDAA99"},{"id":"33b13892f850970e","type":"template","z":"0ded66e5737053d9","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Testing: {{env.TestVar}}","output":"str","x":360,"y":120,"wires":[["6fcc4ac59b03604c"]]},{"id":"0cec4ca1af413cef","type":"inject","z":"0ded66e5737053d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":210,"y":120,"wires":[["33b13892f850970e"]]},{"id":"6fcc4ac59b03604c","type":"debug","z":"0ded66e5737053d9","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":120,"wires":[]},{"id":"f31a6af5a11e30fe","type":"template","z":"0ded66e5737053d9","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Testing: {{{env.TestVarTwo}}}","output":"str","x":360,"y":240,"wires":[["51964b64705566b5"]]},{"id":"c19f3ec0f7961bf3","type":"inject","z":"0ded66e5737053d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":210,"y":240,"wires":[["f31a6af5a11e30fe"]]},{"id":"51964b64705566b5","type":"debug","z":"0ded66e5737053d9","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":240,"wires":[]},{"id":"b4896dcb7005690c","type":"comment","z":"0ded66e5737053d9","name":"Working:","info":"","x":180,"y":80,"wires":[]},{"id":"6e58914ffb2e3286","type":"comment","z":"0ded66e5737053d9","name":"Data from TestVar is not fetched:","info":"","x":250,"y":200,"wires":[]},{"id":"3ca4a95c5435471c","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"d162577bafac2043","type":"subflow:0ded66e5737053d9","z":"3ca4a95c5435471c","name":"","x":180,"y":80,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [10 October 2023 10:02 UTC](https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908/2 "2023-10-10T10:02:06Z")

</div>

Interersting...

**Node RED: 3.1.0**  
**Node : 18.12.0**

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/afea15ef0faac195a4b2c111bc7c5edcfda3cef6.png)

**Node RED: 3.0.2**  
**Node : 18.14.0**

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/52c621643a8465682ac1b65f4f3add7848d51eb2.png)

If others also see this - might be worth raising an issue  
[Issues · node-red/node-red (github.com)](https://github.com/node-red/node-red/issues)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 October 2023 11:27 UTC](https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908/3 "2023-10-10T11:27:25Z")

</div>

It looks like it could be a regression in node-red 3.1.0. I am surprised this is not caught in a test (fairly certain this has unit tests)

The way env vars are evaluated were changed in 3.1.0 (for supporting async JSONata) and this _might_ be a side effect.

It may also be that in v3.0.2 that this was an unintended kind of thing (and why there is no test failure) and thus v3.1.0 has fixed it? (Speculation)

Please raise an issue so it can be investigated.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 October 2023 11:36 UTC](https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908/4 "2023-10-10T11:36:02Z")

</div>

To save anyone loading the flow, the OP is specifying an env var value then using it in the very next row.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/16f7fa909d6976cc3816e389409cd29068cffc33.png)

And while the docs state:

> ### Using the TypedInput widget
> 
> Within the editor, the TypedInput widget can offer ‘environment variable’ as a type. When this type is selected, its value will be evaluated as follows:
> 
> - if there is no `${}` present, uses the whole value as the name of the environment variable. For example, `"FOO"` will be replaced with the value of `process.env.FOO`
> - if `${}` is present, it will substitute the corresponding environment variable into the result: For example, given the value `"Hello ${FOO}"` and the env var `FOO` is set to `World`, this results in the value `"Hello World"`

I am hesitant to call it a bug (as env vars are typically used by the inner nodes) it does appear to be a change of behaviour - something we try to avoid.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [10 October 2023 12:08 UTC](https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908/5 "2023-10-10T12:08:02Z")

</div>

> [@Steve-Mcl](#):
>
> Please raise an issue so it can be investigated.

[Possible bug Joining environment variables in typedInput · Issue #4379 · node-red/node-red (github.com)](https://github.com/node-red/node-red/issues/4379)

---

<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:** [9 December 2023 12:08 UTC](https://discourse.nodered.org/t/possible-bug-joining-environment-variables-in-typedinput/81908/6 "2023-12-09T12:08:29Z")

</div>

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