# Use Environment Variables from .env in custom node client html file

**URL:** <https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111>\
**Category:** Developing Nodes\
**Created:** [13 November 2024 09:58 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111 "2024-11-13T09:58:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pritpalsinghds](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pritpalsinghds/32/96351_2.png) [@pritpalsinghds](https://discourse.nodered.org/u/pritpalsinghds)\
**Post date:** [13 November 2024 09:58 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/1 "2024-11-13T09:58:00Z")

</div>

I am developing a custom Node in Node-RED. This node will allow users to interact with different environments (like **development** , **QA** , and **sandbox** ) by making HTTP requests to a backend API.

I want to make the **default environment** selection dynamic based on the `NODE_ENV` variable defined in my server's `.env` file. The `NODE_ENV` variable can be set to **development** , **qa** , or **sandbox** , and I want the environment field in the configuration form to be pre-filled with the corresponding value from this variable.

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 November 2024 10:35 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/2 "2024-11-13T10:35:46Z")

</div>

Hi and welcome to the forum.

What have you tried so far? Are you familiar with Node.js? And how are you starting up Node-RED?

---

<div class="post-metadata">

**Author:** ![pritpalsinghds](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pritpalsinghds/32/96351_2.png) [@pritpalsinghds](https://discourse.nodered.org/u/pritpalsinghds)\
**Post date:** [13 November 2024 10:46 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/3 "2024-11-13T10:46:44Z")

</div>

tried process.env but it says process is undefined.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [13 November 2024 11:01 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/4 "2024-11-13T11:01:28Z")

</div>

The editor has no access to process variable.

You need to send the value of your environment variable from the runtime to the editor. Example with the udp node:

- Editor

> <https://github.com/node-red/node-red/blob/e48607c74317f047f09035872c9879816a3a0ed3/packages/node_modules/%40node-red/nodes/core/network/32-udp.html#L114-L117>

- Runtime

> <https://github.com/node-red/node-red/blob/e48607c74317f047f09035872c9879816a3a0ed3/packages/node_modules/%40node-red/nodes/core/network/32-udp.js#L133-L135>

---

<div class="post-metadata">

**Author:** ![pritpalsinghds](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pritpalsinghds/32/96351_2.png) [@pritpalsinghds](https://discourse.nodered.org/u/pritpalsinghds)\
**Post date:** [13 November 2024 11:19 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/5 "2024-11-13T11:19:01Z")

</div>

```auto
RED.httpAdmin.get('/udp-ports/:id', RED.auth.needsPermission('udp-ports.read'), function(req,res) {
        res.json(Object.keys(udpInputPortsInUse));
    });

```

What would be the API call for env variables.?

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [13 November 2024 11:24 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/6 "2024-11-13T11:24:44Z")

</div>

Woops, forgot it

```js
const env = RED.util.getSetting(node, "envName")

```

And something like `your-node-type/env`

---

<div class="post-metadata">

**Author:** ![pritpalsinghds](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pritpalsinghds/32/96351_2.png) [@pritpalsinghds](https://discourse.nodered.org/u/pritpalsinghds)\
**Post date:** [13 November 2024 11:39 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/7 "2024-11-13T11:39:34Z")

</div>

I added this const env = RED.util.getSetting(node, "NODE\_ENV"). editor html file But it doesnt work. RED.util is undefined.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [13 November 2024 11:42 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/8 "2024-11-13T11:42:18Z")

</div>

This fonction is for the runtime (your js file).

As I said above, the only way you have in the editor is the `httpAdmin` API.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [13 November 2024 13:17 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/9 "2024-11-13T13:17:13Z")

</div>

Solved by DM.

---

<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:** [12 January 2025 13:17 UTC](https://discourse.nodered.org/t/use-environment-variables-from-env-in-custom-node-client-html-file/93111/10 "2025-01-12T13:17:39Z")

</div>

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