# contextStorage questions

**URL:** <https://discourse.nodered.org/t/contextstorage-questions/14222>\
**Category:** General\
**Created:** [11 August 2019 15:52 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222 "2019-08-11T15:52:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [11 August 2019 15:52 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/1 "2019-08-11T15:52:14Z")

</div>

I have 3 rpi's running node-red 0.2.6 .. one of them doesn't have the // Context Storage section in the system.js file so I tried updating to 0.2.7 .. it seam's to keep the same system.js file even though I updated, so the question is can I just paste in the missing lines from one of the other pi's system.js files ?

Also secondary question, I have one pi working fine with contextStorage if I reboot, the vars I stored in my  
"localfilesystem" are persistent, I can see /home/pi/.node-red/context but that folder is empty, shouldn't I see some file in there that contains my stored vars ?

---

<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:** [11 August 2019 16:25 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/2 "2019-08-11T16:25:03Z")

</div>

> can I just paste in the missing lines from one of the other pi's system.js files

Yes. The settings.js will only be created if it doesn't exist. So, in your case, you need to add the new context settings to your existing settings.js file.

> I can see /home/pi/.node-red/context but that folder is empty, shouldn't I see some file in there that contains my stored vars ?

again yes it should be there. In` /home/pi/.node-red` do you see your flow files?

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [11 August 2019 16:46 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/3 "2019-08-11T16:46:42Z")

</div>

Yes I see my flow files as before but when I added into my setting.js file the following

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

```

After rebooting I see it made a directory called 'context', after I set up some test like  
flow.set('Usage\_count',msg.payload,'localfilesystem'); etc etc tested it was working and when rebooted Usage\_count refreshed its values from ,'localfilesystem' all as expected, however the context directory is still empty, I expected something to be in there, not ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/df648e5dd003afe87e256abb358b0f5a9a188826.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3643fba8ee756776be2d634a356e1cb7d03fbf1f.png)

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [11 August 2019 17:24 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/4 "2019-08-11T17:24:57Z")

</div>

Oh think I may have found problem flow.set('Usage\_count',msg.payload,'localfilesystem') should be flow.set('Usage\_count',msg.payload,'storeInFile') checking if it works !

---

<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:** [11 August 2019 17:27 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/5 "2019-08-11T17:27:28Z")

</div>

It might be helpful to read this thread: [A guide to understanding 'Persistent Context'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/68)

You can have the 'filesystem' be the default so you don't need to specify it.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [11 August 2019 17:51 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/6 "2019-08-11T17:51:17Z")

</div>

OK that was the problem and now it works and I see a file in the context folder containing the persistent data  
Actually I was already following that guide you mentioned, I just made that simple error.

Regarding ' You can have the 'filesystem' be the default so you don't need to specify it.' wouldn't that mean every flow.set I have used in every tab would be saved to file ... that would be hundreds of entry's and I guess slow every thing down, in reality I only want specific data to be persistent but thank you very much for your assistance

---

<div class="post-metadata">

**Author:** ![thatcadguy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thatcadguy/32/5273_2.png) [@thatcadguy](https://discourse.nodered.org/u/thatcadguy)\
**Post date:** [11 August 2019 19:03 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/7 "2019-08-11T19:03:15Z")

</div>

You can add the flushInterval property to your file contextStorage item in settings.js to specify how often you want it to write to disk, by default this is 30 seconds. It doesn't immediately go to disk, so it's quite fast.

---

<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:** [12 August 2019 08:28 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/8 "2019-08-12T08:28:01Z")

</div>

> [@Dave](#):
>
> that would be hundreds of entry's and I guess slow every thing down,

Hundreds of entries?? What are you storing? have you thought about consolidating

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [12 August 2019 09:56 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/9 "2019-08-12T09:56:41Z")

</div>

Sorry I don't understand what you mean .. consolidating  
The tab / flow I am currently developing has 56 flow.set('bla bla , listed below, I currently only need 4 of these to be persistent.  
However I have another 42 tabs I am assuming that if I made 'filesystem' to be the default then every flow.set('bla bla would be saved to file instead of memory, surly that would slow things up.

I do have one question though ... say I do flow.set('Leaf\_this\_month',0,'storeInFile'); that gets saved to file now say I decide to change that to say flow.set('Leaf\_current\_month',0,'storeInFile'); thay are both in the file store so how do I delete the one I no longer want 'Leaf\_this\_month' ?

Do I have to use the change node to delete the whole context store or can i delete a specific items ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/75afbde65dfb9976d5a9a00f2c9b068e6561ea3e.png) Leaf\_countstoreInFile 14459

---

<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:** [12 August 2019 10:02 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/10 "2019-08-12T10:02:38Z")

</div>

> [@Dave](#):
>
> Do I have to use the change node to delete the whole context store or can i delete a specific items

You can set a value to `undefined` and it will be deleted from the store.

---

<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:** [12 August 2019 10:31 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/11 "2019-08-12T10:31:47Z")

</div>

> [@Dave](#):
>
> Sorry I don't understand what you mean .. consolidating

you can store an object. Here is an example function (default is store in file)

```auto
var book ={};
book.author = "Dr. Suess";
book.title = "Mr. Brown can moo, can you?";
book.TimesBorrowed = 27; 
book.WhenDue=Date.now();

flow.set('book',book);
var lent = flow.get('book');
lent.TimesBorrowed++
flow.set('book',lent);
return msg;

```

I don't know if your data can be grouped, this was just a suggestion.

---

<div class="post-metadata">

**Author:** ![Dave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dave/32/10827_2.png) [@Dave](https://discourse.nodered.org/u/Dave)\
**Post date:** [12 August 2019 11:49 UTC](https://discourse.nodered.org/t/contextstorage-questions/14222/12 "2019-08-12T11:49:54Z")

</div>

> [@knolleary](#):
>
> You can set a value to `undefined` and it will be deleted from the store.

Yes it works thanks...  
flow.set("Usage\_this\_month",undefined,'storeInFile');  
refresh browser
