# Node Context does not reset on redeploy

**URL:** <https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733>\
**Category:** General\
**Created:** [24 August 2019 07:36 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733 "2019-08-24T07:36:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![g4ocq](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@g4ocq](https://discourse.nodered.org/u/g4ocq)\
**Post date:** [24 August 2019 07:36 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/1 "2019-08-24T07:36:02Z")

</div>

Hello,

I am scatching my head regarding the node context context.get and context.set

I am finding it does not get reset on a redeploy and the previous values remain.

I have changed my settings.js file to allow some context persistance, when I re-deploy after changing the associated node or even do a full re-deploy the previous values remain.

I changed my settings.js file to:-

contextStorage: {  
default: {module: "memory" },  
InFile: {module: "localfilesystem" },  
},

and save using 'context.set('thermostat', thermostat)'  
I assume as I am not specifying InFile it should be stored in memory and get re-initialsed after a change to the node, if thats not the case I am looking for a way to re-iniatalise these values when I make small changes

---

<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:** [24 August 2019 07:44 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/2 "2019-08-24T07:44:53Z")

</div>

What version of Node-RED are you using?

---

<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:** [24 August 2019 08:16 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/3 "2019-08-24T08:16:54Z")

</div>

> [@g4ocq](#):
>
> I assume as I am not specifying InFile it should be stored in memory and get re-initialsed after a change to the node, if thats not the case I am looking for a way to re-iniatalise these values when I make small changes

No. Deploying a change does not reset context.

You could create a flow that sets your context values to undefined (which is how you delete them) and start it with an Inject node configured to fire on start.

---

<div class="post-metadata">

**Author:** ![g4ocq](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@g4ocq](https://discourse.nodered.org/u/g4ocq)\
**Post date:** [24 August 2019 10:12 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/4 "2019-08-24T10:12:15Z")

</div>

Hi  
my version is 0.20.7.

I have done as reccomended by Nick, thanks. I have an inject node that ends a pulse on start and I set the context to undefined. I just need to remember to deploy any changes to the modified flows, rather than the modified nodes. Too be honest probably what I should be doing anyway to be sure of a proper restart.

---

<div class="post-metadata">

**Author:** ![Lupin\_III](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lupin_iii/32/67650_2.png) [@Lupin\_III](https://discourse.nodered.org/u/Lupin_III)\
**Post date:** [14 April 2020 01:57 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/5 "2020-04-14T01:57:01Z")

</div>

Hi Nick,

> No. Deploying a change does not reset context.  
> You could create a flow that sets your context values to undefined (which is how you delete them) and start it with an Inject node configured to fire on start.

ok for global and flow context, but how can do it for the local context inside the node?

---

<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:** [14 April 2020 07:39 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/6 "2020-04-14T07:39:55Z")

</div>

> [@Lupin\_III](#):
>
> how can do it for the local context inside the node?

Node context _will_ be reset if a node is re-deployed. Obviously it doesn't get reset (and neither should it) if you do a partial deploy not involving that node.

---

<div class="post-metadata">

**Author:** ![Lupin\_III](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lupin_iii/32/67650_2.png) [@Lupin\_III](https://discourse.nodered.org/u/Lupin_III)\
**Post date:** [14 April 2020 11:00 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/7 "2020-04-14T11:00:39Z")

</div>

Is it possible that there is a setting somewhere for this behaviour?  
Or maybe there is something I don't understand properly.  
I put a simple count in a function node, obtaining a certain value after a few inject

> var count=context.get("count")||0;  
> count=count+1;  
> context.set("count",count);

If later on I modify the code inside this node, after redeploy the context count (locale variable) maintain the previous value. It's not "resetted".  
For what I have understood this is because the local context has been already created and it's already existing . So If I want to reset it, I have to manually delete it. Only in this way I have the same behaviour as for the inizial loading, when this local context doesn't exist. And this is what I need.

```auto
[{"id":"361541f.23712be","type":"function","z":"a716f67a.bcc3d8","name":"Prova","func":"msg1={}; msg2={};\nvar count=context.get(\"count\") || 0;\nvar Alm_Status = context.get(\"Alm_Status\")|| false;\ncount=count+1;\nif (count!==0) {\n switch (msg.payload) {\n case false:\n if (Alm_Status===true){\n //do domething\n msg1.payload = \"Reset allarme\"; \n }\n msg2.colour=\"#333333\";\n context.set(\"Alm_Status\",false);\n break;\n case true:\n if (Alm_Status===false){ \n //do domething\n msg1.payload= \"Alarm\"; \n msg2.colour=\"#FF0000\";\n context.set(\"Alm_Status\",true);\n } else {\n msg1=null;\n msg2=null; \n }\n }\n} else {\n msg1 = null;\n switch (msg.payload) {\n case false:\n msg2.colour=\"#333333\";\n Alm_Status = false;\n break;\n case true:\n msg2.colour=\"#FF0000\";\n Alm_Status = true;\n } \n}\ncontext.set(\"count\",count); \nreturn [msg1,msg2];\n","outputs":2,"noerr":0,"x":370,"y":300,"wires":[["adb90e0b.cbcd3"],["91f2127e.c24c4"]]},{"id":"adb90e0b.cbcd3","type":"debug","z":"a716f67a.bcc3d8","name":"DB1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":240,"wires":[]},{"id":"91f2127e.c24c4","type":"debug","z":"a716f67a.bcc3d8","name":"DB2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":320,"wires":[]},{"id":"1c9508de.3b3b27","type":"inject","z":"a716f67a.bcc3d8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":260,"wires":[["361541f.23712be"]]},{"id":"be51da04.0fcfe8","type":"inject","z":"a716f67a.bcc3d8","name":"","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":320,"wires":[["361541f.23712be"]]}]

```

---

<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:** [14 April 2020 11:10 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/8 "2020-04-14T11:10:08Z")

</div>

Hi @Lupin_III

Colin was wrong to say that Node context will be reset if a node is re-deployed - it isn't.

You need to explicitly reset context yourself - you can do it manually using the Context sidebar by selecting the node and deleting the individual bits of node context you want to delete.

---

<div class="post-metadata">

**Author:** ![Lupin\_III](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lupin_iii/32/67650_2.png) [@Lupin\_III](https://discourse.nodered.org/u/Lupin_III)\
**Post date:** [14 April 2020 11:16 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/9 "2020-04-14T11:16:00Z")

</div>

Ok, thanks. Could be really useful to have the possibility of setting this behaviour

---

<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:** [14 April 2020 11:19 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/10 "2020-04-14T11:19:13Z")

</div>

if you are using in-memory context (the default) then stopping and restarting the server will flush it.

---

<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:** [14 April 2020 11:58 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/11 "2020-04-14T11:58:45Z")

</div>

Just to make one small clarification:

if you don't have `contextStorage` configured, then the node context will get cleared on deploy. But if you do have `contextStorage` configured, even if it is the default memory-only store, then it won't get cleared.  
[https://nodered.org/docs/user-guide/context#context-stores](https://nodered.org/docs/user-guide/context#context-stores)

---

<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:** [14 April 2020 12:45 UTC](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/12 "2020-04-14T12:45:33Z")

</div>

That explains my momentary confusion.
