A Node-RED node to monitor a context.
This node allows to setup the reference to a context, then sends a message when this context is written to.
It sends a dedicated message on a separate port in case it detects that the value of the context was changed.
The message sent will carry the current value of the context as msg.payload
, the context key as msg.topic
.
Monitoring details will be provided as msg.monitoring
:
- The monitoring setup:
scope
&key
always,flow
(id) /node
(id) if applicable. - The id of the node that wrote to the context as
source
.
The message sent off the change port carries an additional property in msg.monitoring
:
- The value overwritten as
previous
.
It is possible to monitor an infinite number of contexts with each instance of this node.
This node supports the three context scope levels Global
, Flow
& Node
.
Use the Node-RED palette manager to install this node.
To monitor a Global
scope context, set the scope to Global
and provide the context key.
To monitor a Flow
scope context, set the scope to Flow
, then select the owning flow and provide the context key.
To monitor a Node
scope context, set the scope to Node
, then select flow & node and provide the context key.
Hint: This node doesn't create a context. It just tries to reference to those already existing. If you're referencing a non-existing context, no harm will happen.
You may of course define a setup that monitors objects stored in context.
If you create a reference to this object (stored in context) and write to its properties, this node issues its messages accordingly.
Disclaimer: Monitoring changes to elements of an
Array
currently is not supported.
Monitoring context definition:
Code in a function
node:
// suppose, test_flow = { prop: "value" }
let obj = flow.get("test_flow");
obj.prop = "new";
Message sent by the node:
You may define a setup that doesn't monitor the (whole) object, but only one of its properties:
Such a monitor will react only, when this property and - if it's an object - its child properties are written to.