# Error enabling persistent context

**URL:** <https://discourse.nodered.org/t/error-enabling-persistent-context/12800>\
**Category:** General\
**Created:** [2 July 2019 02:20 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800 "2019-07-02T02:20:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [2 July 2019 02:20 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/1 "2019-07-02T02:20:41Z")

</div>

I'm running NR v0.20.6, Node.js v8.11.2 and trying to enable persistent context storage. In my `settings.js` file,

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

```

works fine, but

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

```

produces this:

> [error] Failed to start server:  
> [error] Error: Error loading context store: SyntaxError: Unexpected token u in JSON at position 0  
> at /usr/local/lib/node\_modules/node-red/node\_modules/@node-red/runtime/lib/nodes/context/index.js:177:15  
> at `<anonymous>`

If this isn't a bug, where should I be looking for my mistake?

---

<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:** [2 July 2019 10:03 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/2 "2019-07-02T10:03:22Z")

</div>

My guess is that you have a corrupted context store file. Whether node-red should fail to start in that case I don't know.  
If you have a look at [https://nodered.org/docs/api/context/store/localfilesystem](https://nodered.org/docs/api/context/store/localfilesystem) it shows you where the context files are stored. If you don't have anything that you need already in the context then if you rename the context folder and start node red then I expect it will recreate it for you. Rename rather than delete, for the moment, in case one of the experts wants to have a look at the contents.

---

<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:** [2 July 2019 15:50 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/3 "2019-07-02T15:50:56Z")

</div>

Well from all that is pasted above there is no config for the localfilesystem so that needs to be defined.

(Yes the error message could be more helpful 🙂

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [2 July 2019 15:54 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/4 "2019-07-02T15:54:16Z")

</div>

> [@Colin](#):
>
> corrupted context store file

That seems to be it. Renamed the context folder, and all seems well. No time to look for the culprit, but I saved the old folder and have a candidate in mind. Thanks! 😀

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [2 July 2019 16:03 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/5 "2019-07-02T16:03:04Z")

</div>

> [@dceejay](#):
>
> no config for the localfilesystem

Not sure what you mean here. When I followed @Colin's advice, NR re-created the files for everything in the flow that used persistent context. It could be better for NR to fall back on memory-only context storage and post a warning in the editor. I might have sorted it eventually on my own, but I really wasn't sure how to proceed.

---

<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:** [2 July 2019 16:10 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/6 "2019-07-02T16:10:41Z")

</div>

Sorry - in the snippet you posted there was no config object to specify the directory so I assumed you had omitted to define it.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [2 July 2019 16:12 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/7 "2019-07-02T16:12:44Z")

</div>

Got it. Bigger snippets next time.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [2 July 2019 17:39 UTC](https://discourse.nodered.org/t/error-enabling-persistent-context/12800/8 "2019-07-02T17:39:31Z")

</div>

> [@dceejay](#):
>
> no config object

In fact, you were right. I used the contextStorage property exactly as it is in the settings.js file on GitHub -- no config object at all. I assumed I would get the defaults. Is that asking for trouble?
