Persistent global context used in template node


This code works perfect in a template node (html) to retrieve cvMode as a global variable... in memory.

Now I installed contrib-persistent-global-context, and with a function node... global.set('cvMode', "ON", "file").
Set & Get work fine.

settings.js contextStorage is set:
contextStorage: {
default: "memoryOnly",
memoryOnly: { module: 'memory' },
file: { module: 'localfilesystem' }

7 Dec 09:17:27 - [info] Node-RED version: v3.1.0
7 Dec 09:17:27 - [info] Node.js version: v18.18.2
7 Dec 09:17:27 - [info] Linux 6.1.0-rpi6-rpi-v8 arm64 LE

How to change value="{{global.cvMode}}" to get the variable from "file" ?

I also tried function getDocGVF which is called by windows.onload as part of :
function getDocGVF() {
document.getElementById('cvMode').value = global.get('cvMode', "file");

Neither worked.

Pls your advise.

oops... the copy lost the code:
input type="text" id="cvMode" name="cvMode" value="{{global.cvMode}}"

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

   code goes here 

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

From template node help text

t is possible to use a property from the flow context or global context. Just use {{}} or {{}} , or for persistable store store use {{flow[store].name}} or {{global[store].name}} .

So {{global[file].cvMode}} should work

Thank You.

  1. I will comply the 3 backticks next time.
    2.Yes, the suggestion works perfect
  2. the template node help text... slipped my attention. Too much focussed on the syntax of set/get.
    Best Regards.

All GlobalVariables work now fine in functions and can be used in html.
On RPi I can observe them landing in directory /home/rpi/.node-red/context/global/global.json.

But when I drag an Inject, the Persistent-Global-Context and a Debug node on a flow, then I get :
"Error: ENOENT: no such file or directory, open 'undefined/GlobalContext.json'"
"Cannot find json file inside [undefined/GlobalContext.json]!" from the Debug node

A Stop/Start of Node-Red does not show errors on the CommandLine of RPi.

What am I missing ?


I don't understand what you mean by that.

There is no need for that, persistent context is built into node-red core.

Thank You.
As there is no need... I removed it, and all works still fine.
As a NR novice I just tried to understand why



I tried it and get the same error. It appears to be a bug in the node. You could report an issue on the node's github page if you wanted to.

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