# A guide to understanding 'Persistent Context'

**URL:** <https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115>\
**Category:** General\
**Created:** [19 October 2018 10:13 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115 "2018-10-19T10:13:24Z")\
**Posts on this page:** 11\
**Page:** 5

<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:** [13 April 2021 20:24 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/85 "2021-04-13T20:24:15Z")

</div>

I'm not sure what you mean by:

> [@Hunter](#):
>
> deletion of stored data is still not included as default option

You can use a `change` node with the `delete option ![Screen Shot 2021-04-13 at 4.23.37 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abce724234525cc34000fa6653d26ed07cc34ac7.png)

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [6 May 2021 22:05 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/86 "2021-05-06T22:05:04Z")

</div>

One of the funniest, accurate explanations of null vs. delete vs. empty (zero), etc... I have ever seen is below... and I discovered it in this forum!

 ![T9M2J](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/707a9752ad18107cf0ff7f607ec568d212aebf9c.png)

---

<div class="post-metadata">

**Author:** ![msongz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msongz/32/41861_2.png) [@msongz](https://discourse.nodered.org/u/msongz)\
**Post date:** [17 May 2021 09:07 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/87 "2021-05-17T09:07:05Z")

</div>

very helpful for understand how to persistent context,  
and this article link should sit inside the template node's help!!!

---

<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:** [17 May 2021 10:25 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/88 "2021-05-17T10:25:47Z")

</div>

Welcome to the forum @msongz

The problem is that context can (and is) used with virtually all nodes, not just the template node. In fact I don't think I have ever used it in a template node. The most common use is probably in the Function node.

---

<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:** [4 June 2021 11:03 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/89 "2021-06-04T11:03:03Z")

</div>

In case it helps anyone, here is a link to a useful example by @Steve-Mcl  
Also read down that thread to find out about saving a context object by 'reference'

> [@Saving a single value to context](https://discourse.nodered.org/t/saving-a-single-value-to-context/46670/6):
>
> { "192.168.1.10": { "last\_on": 1622751269764, "last\_off": 1622751272068 }, "192.16.1.13": { "last\_on": 1622751772269, "last\_off": 1622751774284 } } Working demo updating the values of the objects properties... [{"id":"4d40b13c.c8309","type":"function","z":"1bd2b382.4dd4f4","name":"setup demo data","func":"msg.payload = {\n \"192.168.1.10\": {\n \"last\_on\": 1622751269764,\n \"last\_off\": 1622751272068\n },\n \"192.16.1.13\": {\n \"las…

---

<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 September 2021 10:47 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/90 "2021-09-11T10:47:33Z")

</div>

7 posts were split to a new topic: [Issue with Presistent Context when using q-gate](https://discourse.nodered.org/t/issue-with-presistent-context-when-using-q-gate/50886)

---

<div class="post-metadata">

**Author:** ![u20p17](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/u20p17/32/41780_2.png) [@u20p17](https://discourse.nodered.org/u/u20p17)\
**Post date:** [4 January 2022 09:11 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/91 "2022-01-04T09:11:26Z")

</div>

Hi all,  
I am trying to modify the settings.js like in this post:

> [@Lost](#):
>
> `contextStorage: {`  
> `File	: { module: "localfilesystem"},`  
> `default	: { module: "memory" }`  
> `},`

Therefore I started Node-Red and checked the log where the file is stored:

```auto
start
> node $NODE_OPTIONS node_modules/node-red/red.js "--settings" "/etc/node-red/config.js"
4 Jan 09:53:03 - [info] 
Welcome to Node-RED
===================
4 Jan 09:53:03 - [info] Node-RED version: v2.1.4
4 Jan 09:53:03 - [info] Node.js version: v16.13.1
4 Jan 09:53:03 - [info] Linux 5.10.63-v8 arm64 LE
4 Jan 09:53:05 - [info] Loading palette nodes
4 Jan 09:53:11 - [info] Dashboard version 3.1.3 started at /endpoint/ui
4 Jan 09:53:14 - [info] Settings file : /etc/node-red/config.js
4 Jan 09:53:14 - [info] Context store : 'default' [module=memory]
4 Jan 09:53:14 - [info] User directory : /config/node-red/
4 Jan 09:53:14 - [warn] Projects disabled : editorTheme.projects.enabled=false
4 Jan 09:53:14 - [info] Flows file : /config/node-red/flows.json
4 Jan 09:53:15 - [info] Server now running at http://127.0.0.1:46836/
4 Jan 09:53:15 - [info] Starting flows

```

As you can see it should be stored in /etc/node-red/config.js, but I can not find this folder. I connected via ssh and logged in with root and the pw.but I can not find the file:

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

What could be the problem?

Thanks

---

<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:** [4 January 2022 10:00 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/92 "2022-01-04T10:00:53Z")

</div>

Have you looked in `/config/node-red/`?

Also, have you saved any values in file context?

---

<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:** [4 January 2022 12:35 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/93 "2022-01-04T12:35:33Z")

</div>

Since you have the `default` set to memory, you need to specify when you want it to be saved into the file. For example, in a `change` node you will have to pick the 'File' option

 ![Screen Shot 2022-01-04 at 7.33.12 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e4612645ffe01b5c23fbe48f279867d2032d230.png)  
or it will default to memory.

If you want it to default to the filesystem, change the settings.js to

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

```

EDIT: you should also read [Working with context : Node-RED](https://nodered.org/docs/user-guide/context)  
and [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions)

---

<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:** [4 January 2022 12:47 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/94 "2022-01-04T12:47:12Z")

</div>

> [@u20p17](#):
>
> As you can see it should be stored in /etc/node-red/config.js, but I can not find this folder.

It is only there because that's where you told it you wanted it to be when you started Node-RED - line 2 of your output. I don't believe that is a normal option for a default installation of Node-RED. How did you install Node-RED?

What happens if you do `cd /etc/node-red`? Do you get an error?

---

<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:** [31 August 2022 08:08 UTC](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115/96 "2022-08-31T08:08:54Z")

</div>



[Previous page](https://discourse.nodered.org/t/a-guide-to-understanding-persistent-context/4115.md?page=4)
