# How to get environment variables in a custom node

**URL:** https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525
**Category:** General
**Created:** [11 January 2023 10:27 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525 "2023-01-11T10:27:59Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![LeungChunChiu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leungchunchiu/32/63211_2.png) [@LeungChunChiu](https://discourse.nodered.org/u/LeungChunChiu)
#### Post date: [11 January 2023 10:27 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/1 "2023-01-11T10:27:59Z")

</div>

Hello, I created a custom node, but I don't know how to access environment variables in the custom node

pls help, thanks!

---

<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: [11 January 2023 10:34 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/2 "2023-01-11T10:34:23Z")

</div>

You can use:

```javascript
RED.util.getSetting(node, 'ENV_VAR')

```

---

<div class="post-metadata">

### Author: ![watadarkstar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/watadarkstar/32/74216_2.png) [@watadarkstar](https://discourse.nodered.org/u/watadarkstar)
#### Post date: [20 January 2023 16:41 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/3 "2023-01-20T16:41:39Z")

</div>

> [@knolleary](#):
>
> ```auto
> RED.util.getSetting(node, 'ENV_VAR')
> 
> ```

Thanks! This helped. Where is the documentation for this?

---

<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: [20 January 2023 16:44 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/4 "2023-01-20T16:44:51Z")

</div>

I thought it was covered in [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables) - but that is more end-user facing docs.

We should add something to [JavaScript file : Node-RED](https://nodered.org/docs/creating-nodes/node-js)

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [20 January 2023 17:03 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/5 "2023-01-20T17:03:24Z")

</div>

Is there a difference to `process.env['ENV_VAR']` ... for a custom node?

---

<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: [20 January 2023 17:10 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/6 "2023-01-20T17:10:29Z")

</div>

> [@ralphwetzel](#):
>
> Is there a difference to `process.env['ENV_VAR']`

Within Node-RED, you can set properties that are scoped to individual subflows or flows. They show up as env vars to the nodes - as long as they use `RED.util.getSetting(node, 'ENV_VAR')`. This is why the call includes the node object - so the runtime can look up the right value for that particular node depending on what flow/subflow its in.

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [20 January 2023 19:09 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/7 "2023-01-20T19:09:46Z")

</div>

Thank you for this explanation! 👍

---

<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: [21 March 2023 19:10 UTC](https://discourse.nodered.org/t/how-to-get-environment-variables-in-a-custom-node/73525/8 "2023-03-21T19:10:01Z")

</div>

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