# Store a value and reinsert it when flows start

**URL:** <https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877>\
**Category:** General\
**Created:** [9 July 2022 15:01 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877 "2022-07-09T15:01:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [9 July 2022 15:01 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/1 "2022-07-09T15:01:28Z")

</div>

I calculate the cost for my power consumption each hour and I put the different values into a Sum-node. This works fine, but I have noticed that if the flows restart the sum-node is empty. Is it possible to make a function node to store the value and reinsert it into the sum-node if the flows restart?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [9 July 2022 15:28 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/2 "2022-07-09T15:28:00Z")

</div>

Have a look here:  
[https://nodered.org/docs/user-guide/context](https://nodered.org/docs/user-guide/context)

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [9 July 2022 19:50 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/3 "2022-07-09T19:50:43Z")

</div>

Isn't it better to have a look why the flow restarts.

---

<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:** [9 July 2022 21:01 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/4 "2022-07-09T21:01:19Z")

</div>

I assumed that @FSHelgeland was referring to normal reboot, deploys etc rather than unexpected restarts. Certainly if it is restarting for unknown reasons then that should be addressed.

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 01:29 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/5 "2022-07-10T01:29:31Z")

</div>

Colin is absolutely correct, I seldom have to restart my Node Red do to faults or unexpected things. But since I am still pretty new programming and since I am still testing a lot of stuff I do some reebooting and deploys from time to time. And I think it is a good thing to know how to do a memory in Node Red as well.

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 14:06 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/6 "2022-07-10T14:06:55Z")

</div>

I understand that i have to uncomment some lines in the settings.js to get to work with context it that correct? And when I try to enter my settings.js it looks like it is read only, at least I can not gett access to it.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [10 July 2022 14:12 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/7 "2022-07-10T14:12:47Z")

</div>

> [@FSHelgeland](#):
>
> And when I try to enter my settings.js it looks like it is read only

What environment? If linux try "sudo nano...."

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 14:16 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/8 "2022-07-10T14:16:00Z")

</div>

It is on a raspberry pi. What should I type then? Just sudo nano?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [10 July 2022 14:17 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/9 "2022-07-10T14:17:36Z")

</div>

If you did not get that hint, I have to encourage you to read up a bit more on Node-RED and settings.js etc

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 14:23 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/10 "2022-07-10T14:23:15Z")

</div>

Trust me, I do.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [10 July 2022 14:32 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/11 "2022-07-10T14:32:07Z")

</div>

Find out where you have the settings.js file located

As example in /home/pi/.node-red

So you would type

"sudo nano /home/pi/.node-red/settings.js" and there you go and can make the edits you need

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 14:34 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/12 "2022-07-10T14:34:07Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 14:57 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/13 "2022-07-10T14:57:02Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/103a35ce025e5bb4d768b59c8715fb96203ad6cf.png)

Will this be correct?

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [10 July 2022 15:00 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/14 "2022-07-10T15:00:07Z")

</div>

> [@krambriw](#):
>
> What environment? If linux try "sudo nano...."

You should NOT need sudo, it could lead to problems.

---

<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:** [10 July 2022 15:07 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/15 "2022-07-10T15:07:52Z")

</div>

+1 to that. If you need to use sudo you are probably trying to edit the wrong settings.js.

---

<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:** [10 July 2022 15:16 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/16 "2022-07-10T15:16:09Z")

</div>

Here is a topic I wrote (quite awhile ago) that may help you out

> [@A guide to understanding 'Persistent Context'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115):
>
> This is something I wrote up after playing with the context options. I've filed a PR with some of this added to the Node-RED documentation but thought I'd release it here also. I hope people find it useful. Paul A guide to understanding 'Persistent Context' Prior to Node-RED v0.19.0, data could be stored in context as a global, flow or node. This was stored in memory and would be reset with a restart of Node-RED. As of v.0.19.0 you can now store node, flow and global context data in memory O…

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 15:26 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/17 "2022-07-10T15:26:07Z")

</div>

Getting more and more confused @Colin I just need to uncomment in settings so I am able to use context. Did unable what shown above with sudo nano command but that did not seem to do the trick. But if I try to access the file without the sudo nano command I can not access the file.

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 17:30 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/18 "2022-07-10T17:30:12Z")

</div>

Ok,so i finally succed in to do the neccesary changes in settings.js but I now get an error:

10 Jul 19:25:29 - [error] Uncaught Exception:  
10 Jul 19:25:29 - [error] Error: listen EADDRINUSE: address already in use 0.0.0.0:1880  
at Server.setupListenHandle [as \_listen2] (net.js:1331:16)  
at listenInCluster (net.js:1379:12)  
at doListen (net.js:1516:7)  
at processTicksAndRejections (internal/process/task\_queues.js:83:21)

Probably due to Home assistant was already using context to file.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/a/daef51a8dc09f78bf19f1b22e6827ccbabcc03e1.png)

Will that be a problem, and what should I do to fix it?

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [10 July 2022 17:38 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/19 "2022-07-10T17:38:17Z")

</div>

> [@FSHelgeland](#):
>
> address already in use 0.0.0.0:1880

Do you have two instances of Node-RED running?? Port 1880 is used by Node-RED

EDIT: maybe that's why you could not edit settings.js, it is locked by a running instance??. Check with command "ps aux" or "top" and check your running processes

---

<div class="post-metadata">

**Author:** ![FSHelgeland](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fshelgeland/32/64260_2.png) [@FSHelgeland](https://discourse.nodered.org/u/FSHelgeland)\
**Post date:** [10 July 2022 17:49 UTC](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877/20 "2022-07-10T17:49:54Z")

</div>

will have a look into that.

[Next page](https://discourse.nodered.org/t/store-a-value-and-reinsert-it-when-flows-start/64877.md?page=2)
