# contextStorage in later versions of NR. Confused

**URL:** <https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755>\
**Category:** General\
**Created:** [24 October 2020 21:44 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755 "2020-10-24T21:44:42Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 October 2020 21:44 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/1 "2020-10-24T21:44:42Z")

</div>

NR 1.1.2

[From this link](https://nodered.org/docs/api/context/store/localfilesystem)  
`New in 0.19` So I believe I am included in this.

```auto
contextStorage: {
   default: {
       module:"localfilesystem",
       config: {
           // see below
       }
   }
}

```

So, off I go to `settings.js`.  
`contextStorage`  
**not found**

Looking.....

```auto
    // Anything in this hash is globally available to all functions.
    // It is accessed as context.global.
    // eg:
    // functionGlobalContext: { os:require('os') }
    // can be accessed in a function block as:
    // context.global.os

    functionGlobalContext: {
        // os:require('os'),
        // octalbonescript:require('octalbonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})
        myDeviceName: "BedPi"
    },

```

So we have gone from `contextStorage` to `functionGlobalContext`.

How do I set it up so context is stored in/on the filesystem?

(Just to check:)  
(now things are getting vague for me)

I have seen some nodes talking about context (`gate` for instance) but then the `switch/button` node has no mention of this.

I want the `switch` (as in dashboard type) to get their previous state back if the machine is rebooted.

Is this the better way of doing it?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 October 2020 22:03 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/2 "2020-10-24T22:03:09Z")

</div>

How old is the settings.js file?  
It's easy to keep updating node-RED (which does not update the settings.js file), and then find that new options have been added which require a setting in the settings file.  
Compare your settings file with the current version - available from github.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 October 2020 22:05 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/3 "2020-10-24T22:05:39Z")

</div>

(Me showing my stupidity.)

Thanks.

So next dumb question: How do I make the `settings.js` file up to date?

My efforts at finding the latest `settings.js` file on github are only showing stuff that are old.  
Like \> 2 years ago.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 October 2020 22:07 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/4 "2020-10-24T22:07:55Z")

</div>

> [@Trying\_to\_learn](#):
>
> So next dumb question: How do I make the `settings.js` file up to date?

As I have already said;

> [@Paul-Reed](#):
>
> Compare your settings file with the current version - available from github

If you just want to add the context storage, just add & edit this, to your settings;

```auto
    // Context Storage
    // The following property can be used to enable context storage. The config$
    // provided here will enable file-based context that flushes to disk every $
    // Refer to the documentation for further options: https://nodered.org/docs$
    //
    //contextStorage: {
    // default: {
    // module:"localfilesystem"
    // },
    //},

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 October 2020 22:08 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/5 "2020-10-24T22:08:45Z")

</div>

So the part I posted is....... redundant? Superfluous? not needed/used?

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 October 2020 22:10 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/6 "2020-10-24T22:10:01Z")

</div>

> [@Trying\_to\_learn](#):
>
> So the part I posted is

What part?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 October 2020 22:10 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/7 "2020-10-24T22:10:33Z")

</div>

This:

```auto
// Anything in this hash is globally available to all functions.
    // It is accessed as context.global.
    // eg:
    // functionGlobalContext: { os:require('os') }
    // can be accessed in a function block as:
    // context.global.os

    functionGlobalContext: {
        // os:require('os'),
        // octalbonescript:require('octalbonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})
        myDeviceName: "BedPi"
    },

```

Oh, is that more for `global context` rather than general context?

As I said: I'm confused.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 October 2020 22:11 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/8 "2020-10-24T22:11:50Z")

</div>

> [@Trying\_to\_learn](#):
>
> So the part I posted is....... redundant?

That isn't the section that you need.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 October 2020 22:14 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/9 "2020-10-24T22:14:32Z")

</div>

Ok, so I may not be actually doing the right thing then.

I'm not sure.

If I want the `switch` nodes to go back to the state they were in before an unexpected reboot, is that under this of which I am now asking - or that you showed me - or something else?  
And other things as well.

Reboots can be painful if I am not here/on site.

I get that some things will _default_ to things, but a lot of stuff I want to go back to how it was before the reboot.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 October 2020 22:18 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/10 "2020-10-24T22:18:23Z")

</div>

> [@Trying\_to\_learn](#):
>
> Ok, so I may not be actually doing the right thing then.

Correct.  
See [node-red/packages/node\_modules/node-red/settings.js at master · node-red/node-red · GitHub](https://github.com/node-red/node-red/blob/master/packages/node_modules/node-red/settings.js#L255-L264)  
This is what you need to establish context storage.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [24 October 2020 22:22 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/11 "2020-10-24T22:22:43Z")

</div>

I hope it works.

Obviously I removed the leading `//` on the required lines and I had to restart NR.

---

<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:** [25 October 2020 00:12 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/12 "2020-10-25T00:12:16Z")

</div>

Andrew, maybe this will help too

> [@A guide to understanding 'Persistent Context'](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/71):
>
> It depends on what you have set for the default. Did you read the documentation and the write up I did ?

---

<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:** [8 November 2020 00:12 UTC](https://discourse.nodered.org/t/contextstorage-in-later-versions-of-nr-confused/34755/13 "2020-11-08T00:12:34Z")

</div>

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