A node can store data within its context object. This context object is reset whenever the node is redeployed and when Node-RED is restarted.
// Access the node's context object
var context = this.context();
var count = context.get('count') || 0;
count += 1;
context.set('count',count);
The flow-level context is shared by all nodes on a given tab.
var flowContext = this.context().flow;
var count = flowContext.get('count')||0;
The global context is shared by, and accessible to all nodes. For example to
make the variable foo
available globally:
var globalContext = this.context().global;
globalContext.set("foo","bar"); // this is now available to other nodes
In the Function node, the flow
and global
context objects are made available
a top-level objects. See this section
for more information.