# Reload global variables after deploy/restart

**URL:** https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135
**Category:** Core Development
**Created:** [13 May 2018 01:56 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135 "2018-05-13T01:56:56Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)
#### Post date: [13 May 2018 01:56 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/1 "2018-05-13T01:56:56Z")

</div>

If I understood well this is the place where we can make some improvement request right?

If I’m right I think a huge amount of people will be interested that node red has native capability to recover all global variables after deploy/restart.

This will be great and will release the job to be making tricks with MQTT or saving variable by variable to a file etc…

Thanks in advnace

---

<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: [13 May 2018 07:09 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/2 "2018-05-13T07:09:11Z")

</div>

Hi @davidcgu

Persistable Context is already on the roadmap and in fact we already have a pull request that implements it for the 0.19 release.

Nick

---

<div class="post-metadata">

### Author: ![yesdred](https://avatars.discourse-cdn.com/v4/letter/y/e274bd/32.png) [@yesdred](https://discourse.nodered.org/u/yesdred)
#### Post date: [15 May 2018 18:41 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/3 "2018-05-15T18:41:19Z")

</div>

Perfect. My idea was to ‘store’ variable contents in a retained message and use an Inject node at start to subscribe to the storage topic and store the value again. I was going to ask how best to accomplish this (subscribe in a function, get the payload once, store it in a variable and kill the subscription) but now I rather wait for 0.19.

---

<div class="post-metadata">

### Author: ![yesdred](https://avatars.discourse-cdn.com/v4/letter/y/e274bd/32.png) [@yesdred](https://discourse.nodered.org/u/yesdred)
#### Post date: [18 May 2018 10:43 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/4 "2018-05-18T10:43:41Z")

</div>

I looked at the PR. If I understand it correctly, variables are persisted by writing their content to files. I wonder if this better for the hardware (e.g. a Raspberry Pi’s SD card) than retained messages (which are stored also in the file system in a database).

---

<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: [18 May 2018 13:27 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/5 "2018-05-18T13:27:15Z")

</div>

Mosquitto’s database is a simple file DB anyway. File handling is generally very efficient these days and you really don’t see much benefit from a managed DB until you are able to keep indexes fully in memory - not a lot of benefit when the purpose is to reload to memory anyway.

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [28 January 2019 11:29 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/6 "2019-01-28T11:29:19Z")

</div>

I have the opposite problem, I need to send some data to hardware to initialize it at every deploy, I?m using a global variable that if undefined will be "0" and at every single event generated by a cyclic Inject increase its value till the data is finished, in my case after 10 data sent cycles, than the main flow can use the hardware if 10 is riched, not before.  
WHen I deploy the valuse is already 10.. how can I force it to zero? Thank you

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [28 January 2019 11:56 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/7 "2019-01-28T11:56:39Z")

</div>

> [@GiovanniG](#):
>
> WHen I deploy the valuse is already 10.. how can I force it to zero? Thank you

I could use an inject node (select `Inject once`) and wire it to a change node that set the global variable to 0;

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [28 January 2019 11:58 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/8 "2019-01-28T11:58:44Z")

</div>

Thank you for kind reply, I solved used "contribute config" module and I set there the variable to 0..

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [28 January 2019 12:16 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/9 "2019-01-28T12:16:32Z")

</div>

The default for context is still to use memory which doesn't survive restarts.

So what you can do is to define that for that variable you want to use memory connect store

eg

```auto
flow.set("count", 123, storeName);

```

see [https://nodered.org/docs/writing-functions#storing-data](https://nodered.org/docs/writing-functions#storing-data)

---

<div class="post-metadata">

### Author: ![GiovanniG](https://avatars.discourse-cdn.com/v4/letter/g/ecd19e/32.png) [@GiovanniG](https://discourse.nodered.org/u/GiovanniG)
#### Post date: [28 January 2019 12:22 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/10 "2019-01-28T12:22:16Z")

</div>

Then Global will persist but context and flow will be reset on every deploy?

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [28 January 2019 12:36 UTC](https://discourse.nodered.org/t/reload-global-variables-after-deploy-restart/135/11 "2019-01-28T12:36:12Z")

</div>

See

> [@tada Node-RED 0.19 released](https://discourse.nodered.org/t/node-red-0-19-released/2267/23):
>
> @Paul-Reed @TotallyInformation you configure multiple stores by having multiple configs listed: contextStorage: { default: { module: "localfilesystem" }, memoryOnly: { module: "memory" } }, Then, [as per the docs](https://nodered.org/docs/writing-functions#multiple-context-stores) you can use either default or memoryOnly as the store name argument of context.get/set. Also, once you have multiple stores configured, the TypedInput has an extra drop-down to pick the store to use. Will update the docs.

If you define a memory only context store, you can write specific data to that which will be flushed by a restart, where as other data is written to the default which if you have defined it is saved to the localfilesystem and survives a restart
