# Config node context and persistency after deployment

**URL:** <https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354>\
**Category:** Developing Nodes\
**Created:** [8 July 2024 14:17 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354 "2024-07-08T14:17:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomassorensen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thomassorensen/32/45692_2.png) [@Thomassorensen](https://discourse.nodered.org/u/Thomassorensen)\
**Post date:** [8 July 2024 14:17 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354/1 "2024-07-08T14:17:49Z")

</div>

I’m seeing some strange behaviour when using context on a config node..

If I set a value in node context from custom configuration node using:  
`this.context().set("s", "Hello")`

Then I can read the value back using `this.context().get("s")` as expected. But if I redeploy the flows, then `this.context().get("s")` will return undefined.

Everything works as expected if I use `this.context().global.set("s", "Hello")` and `this.context().global.get("s")` - even after redeploying flows

Is this expected behaviour? This seems to work for "non config" nodes even after redeployment of flows.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [8 July 2024 20:38 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354/2 "2024-07-08T20:38:39Z")

</div>

I believe it is.

`this.context()` refers to the 'instance' context of the Node (at least for a config node)  
if a Config Node is redeployed, the instance is destroyed and recreated, during deploy.

The argument here, is why `this.context` survives for None Node Configs - so I see why its been asked

@Steve-Mcl ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 July 2024 20:48 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354/3 "2024-07-08T20:48:17Z")

</div>

Not an area i have delved into. What I will say is it is very likely this is unnecessary.

When a (config) node is instantiated and has its own `this` so things to store can be stored in `this.that` or `this.other`.

> [@Thomassorensen](#):
>
> But if I redeploy the flows, then `this.context().get("s")` will return undefined.

If you modify the config node OR do a full deploy, then that is expected unless context is persistent. And if that is the idea, then you should be storing the value in a property that gets written to the flow.

---

<div class="post-metadata">

**Author:** ![Thomassorensen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thomassorensen/32/45692_2.png) [@Thomassorensen](https://discourse.nodered.org/u/Thomassorensen)\
**Post date:** [10 July 2024 13:40 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354/4 "2024-07-10T13:40:36Z")

</div>

Thanks for the reply. That makes sense, but it just seemed inconsistent/odd that this works for "non config" nodes and global context, but not for config nodes.

Is there another way for me to store a value between redeploys? (other than storing in global context or asking all users to setup a persistent context store).

I'm implementing a protocol that requires me to increase an id every time the node reconnect, so I need a place to store this last id between redeployments (I dont need persistency between node-red restart).

---

<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:** [10 July 2024 14:26 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354/5 "2024-07-10T14:26:55Z")

</div>

> [@Thomassorensen](#):
>
> Is there another way for me to store a value between redeploys? (other than storing in global context or asking all users to setup a persistent context store).

You could implement your own "store" by updating a file from within your node's runtime.

---

<div class="post-metadata">

**Author:** ![Thomassorensen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thomassorensen/32/45692_2.png) [@Thomassorensen](https://discourse.nodered.org/u/Thomassorensen)\
**Post date:** [13 July 2024 19:45 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354/6 "2024-07-13T19:45:02Z")

</div>

Thats not a bad idea, that is probably the way I need to go, but it still seems like a bug that it's not consistent with how normal node context works.

> [@Node Context does not reset on redeploy](https://discourse.nodered.org/t/node-context-does-not-reset-on-redeploy/14733/3):
>
> 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:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 September 2024 19:45 UTC](https://discourse.nodered.org/t/config-node-context-and-persistency-after-deployment/89354/7 "2024-09-11T19:45:44Z")

</div>

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