# Whats wrong here with getting enviroment variables?

**URL:** <https://discourse.nodered.org/t/whats-wrong-here-with-getting-enviroment-variables/81105>\
**Category:** General\
**Created:** [7 September 2023 12:52 UTC](https://discourse.nodered.org/t/whats-wrong-here-with-getting-enviroment-variables/81105 "2023-09-07T12:52:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haegar33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haegar33/32/38805_2.png) [@haegar33](https://discourse.nodered.org/u/haegar33)\
**Post date:** [7 September 2023 12:52 UTC](https://discourse.nodered.org/t/whats-wrong-here-with-getting-enviroment-variables/81105/1 "2023-09-07T12:52:21Z")

</div>

Just updated to V3.1 and now, for the first time, wanna try to use global enviroment variables. But I am already stucked with this first example. Output is `nil` or `undefined`  
An enviroment variable `NAME` has been defined via the new editor.

```auto
[
    {
        "id": "3412699fcff8c757",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "5fbc9d8c656aa129",
        "type": "inject",
        "z": "3412699fcff8c757",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "${NAME}",
        "payloadType": "env",
        "x": 350,
        "y": 360,
        "wires": [
            [
                "429749928b1530b7",
                "c1be07a0c1ea5915"
            ]
        ]
    },
    {
        "id": "429749928b1530b7",
        "type": "debug",
        "z": "3412699fcff8c757",
        "name": "setting_out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 360,
        "wires": []
    },
    {
        "id": "c1be07a0c1ea5915",
        "type": "function",
        "z": "3412699fcff8c757",
        "name": "function 1",
        "func": "var nmsg = { \"payload\" : env.get('NAME')};\nreturn nmsg",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 280,
        "wires": [
            [
                "b7ad803777339e0a"
            ]
        ]
    },
    {
        "id": "b7ad803777339e0a",
        "type": "debug",
        "z": "3412699fcff8c757",
        "name": "func_out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 280,
        "wires": []
    }
]

```

---

<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:** [7 September 2023 13:19 UTC](https://discourse.nodered.org/t/whats-wrong-here-with-getting-enviroment-variables/81105/2 "2023-09-07T13:19:10Z")

</div>

Hi @haegar33

In your Inject node, the property should be `NAME` not `${NAME}`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/be2ced0de060dfd5b56484f9bbd5c51662e6290d.png)

As you have set the field type as 'env var', if you use `${NAME}` then the runtime will first substitute the value of `${NAME}` with the value of the `NAME` env var... which is then used as the name of the env var to lookup for the field...

---

<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:** [6 November 2023 13:19 UTC](https://discourse.nodered.org/t/whats-wrong-here-with-getting-enviroment-variables/81105/3 "2023-11-06T13:19:21Z")

</div>

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