A guide to understanding 'Persistent Context'

I'm not sure what you mean by:

You can use a change node with the `delete optionScreen Shot 2021-04-13 at 4.23.37 PM

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!

8 Likes

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

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.

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'

2 Likes

7 posts were split to a new topic: Issue with Presistent Context when using q-gate

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

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

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:

What could be the problem?

Thanks

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

Also, have you saved any values in file context?

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


or it will default to memory.

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

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

EDIT: you should also read Working with context : Node-RED
and Writing Functions : Node-RED

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?