# How to set env variable

**URL:** <https://discourse.nodered.org/t/how-to-set-env-variable/18612>\
**Category:** General\
**Created:** [29 November 2019 14:33 UTC](https://discourse.nodered.org/t/how-to-set-env-variable/18612 "2019-11-29T14:33:28Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 December 2019 09:53 UTC](https://discourse.nodered.org/t/how-to-set-env-variable/18612/21 "2019-12-01T09:53:12Z")

</div>

> [@DemonKing](#):
>
> Could you tell me how to create a custom nodes

Have a look in the node red docs.

Possibly the best way would be to first look at the code of the current node, then when you think you understand it, fork that repository and amend that node to do what you want. Once it is working you can send the changes back to the author as a PR to get it included in the standard node.  
In fact first raise an issue on the node and offer to help the author implement the feature.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 December 2019 09:56 UTC](https://discourse.nodered.org/t/how-to-set-env-variable/18612/22 "2019-12-01T09:56:24Z")

</div>

> [@Trying\_to\_learn](#):
>
> Use DNS and access it by the name rather than the IP

Again that won't work if the node makes a connection to the DB on startup and does not have the code to disconnect and connect to a different db.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [1 December 2019 10:11 UTC](https://discourse.nodered.org/t/how-to-set-env-variable/18612/23 "2019-12-01T10:11:42Z")

</div>

This would have to be an optional behaviour if you wanted to update the existing node. Having to check then closing and reopening the connection all the time could potentially make the performance really bad if not implemented properly.

---

<div class="post-metadata">

**Author:** ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)\
**Post date:** [15 July 2022 21:59 UTC](https://discourse.nodered.org/t/how-to-set-env-variable/18612/24 "2022-07-15T21:59:41Z")

</div>

> [@knolleary](#):
>
> You cannot change env vars dynamically. We do not expose the `process` object in the Function node. That is just how it is.

Wanted to know if this still is the case ? I could not see any documentation on this.

I was able to set an env variiable using function node.

1. On Set up :- Import process module into variable "process".
2. On Start Up :- process.env.x="XXX";
3. Now i am able to access x as env variable across the system.

I could use in a normal inject node.

---

<div class="post-metadata">

**Author:** ![paulkeates](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@paulkeates](https://discourse.nodered.org/u/paulkeates)\
**Post date:** [16 September 2022 14:53 UTC](https://discourse.nodered.org/t/how-to-set-env-variable/18612/25 "2022-09-16T14:53:24Z")

</div>

Hi,

There is now a node called: node-red-contrib-mysql2 that can absolutely do what you need. You set the configuration (including credentials) in a JSON object, and it will connect to multiple different MYSQL DB's. Obviously it introduces the risk of people getting your DB credentials from the Node-RED flow, but I was willing to make that trade-off.

Cheers,

Paul

[Previous page](https://discourse.nodered.org/t/how-to-set-env-variable/18612.md?page=1)
