# Global/Context Variables

**URL:** https://discourse.nodered.org/t/global-context-variables/70705
**Category:** General
**Created:** [16 November 2022 11:26 UTC](https://discourse.nodered.org/t/global-context-variables/70705 "2022-11-16T11:26:35Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Xanathon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xanathon/32/70833_2.png) [@Xanathon](https://discourse.nodered.org/u/Xanathon)
#### Post date: [16 November 2022 11:26 UTC](https://discourse.nodered.org/t/global-context-variables/70705/1 "2022-11-16T11:26:36Z")

</div>

Hello,

I'm somewhat new to NodeRED, but enjoying it very much and already was able to solve a lot of questions from the docs and this forum.

However:

For my production flows in a business context I need global variables, those will change very seldom, maybe once every few months or once a year. They will need to be present at Node-RED startup. I already found information in forum discussions and the documentation. I know that I can add global context variables to the settings.js file.

I think that is somewhat cumbersome and prone to errors. And I think it may be not the best way to tinker with a settings file just to set a few global variables.

Is there a better way to do this?  
Can it be considered by the devs to add a settings dialog to the Node-RED UI to set those variables?

Thanks for your help and insights in advance.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [16 November 2022 11:30 UTC](https://discourse.nodered.org/t/global-context-variables/70705/2 "2022-11-16T11:30:16Z")

</div>

So why not have a flow to store the values into global context?

---

<div class="post-metadata">

### Author: ![Xanathon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xanathon/32/70833_2.png) [@Xanathon](https://discourse.nodered.org/u/Xanathon)
#### Post date: [16 November 2022 11:32 UTC](https://discourse.nodered.org/t/global-context-variables/70705/3 "2022-11-16T11:32:31Z")

</div>

Thanks for your answer.

Are all flows informations available when (other) flows run? Is something like this initialized at start? Can I make sure the flow setting the variables is run first (is there a "run at startup"-Trigger)?

**Edit** : Just found the answer myself: [Trigger a flow whenever Node-RED starts : Node-RED](https://cookbook.nodered.org/basic/trigger-on-start)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [16 November 2022 11:39 UTC](https://discourse.nodered.org/t/global-context-variables/70705/4 "2022-11-16T11:39:34Z")

</div>

You will want to change settings.js to store the context data on disk so it will be there over stop/starts of NR.

```auto
     	contextStorage: {
			default : { module: "localfilesystem" },
 			memory : { module: "memory" }
     	},

```

---

<div class="post-metadata">

### Author: ![Xanathon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xanathon/32/70833_2.png) [@Xanathon](https://discourse.nodered.org/u/Xanathon)
#### Post date: [16 November 2022 11:41 UTC](https://discourse.nodered.org/t/global-context-variables/70705/5 "2022-11-16T11:41:54Z")

</div>

Yes, I know that. See my opening post. I mentioned that option in it and akeded if a better solution could be possible or implemented instead of manually editing a settings file.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [16 November 2022 11:48 UTC](https://discourse.nodered.org/t/global-context-variables/70705/6 "2022-11-16T11:48:23Z")

</div>

You only edit the settings file `once`, after that - with my example - the default for context data will be in storage so stopping NR and restarting it, the data will still remain.

Here is a post I wrote quite a while ago about presistant context you might find helpful:

[https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/96](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/96)

---

<div class="post-metadata">

### Author: ![Xanathon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xanathon/32/70833_2.png) [@Xanathon](https://discourse.nodered.org/u/Xanathon)
#### Post date: [16 November 2022 11:59 UTC](https://discourse.nodered.org/t/global-context-variables/70705/7 "2022-11-16T11:59:14Z")

</div>

Thanks again! Very helpful.

---

<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: [15 January 2023 11:59 UTC](https://discourse.nodered.org/t/global-context-variables/70705/8 "2023-01-15T11:59:14Z")

</div>

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