How do you set a 'node' context variable?

#1

In the documentation it talks about the 'scope' of a particular context. Global and flow I understand, but not node. To set a flow context variable you use something like
flow.set("myData", msg.payload, "storeInFile");
and in the sidebar you can see the value.
21%20PM

There is an area to display Node context, but how do you set it? If I use
node.set("myData", msg.payload);
I get:
28 Sep 00:52:14 - [error] [function:Node Stored in memory] TypeError: node.set is not a function
so my question: How do you set a node context?

0 Likes

#2
context.set("myData", msg.payload);

https://nodered.org/docs/writing-functions#storing-data

0 Likes

#3

Duh (head slap) I must have read that 3 times and it went in and out my head. (Can I blame my head cold?)
Thanks @knolleary !

0 Likes

#4

@knolleary
One more question - when I use context.set("myData", msg.payload); It will only show up in the sidebar if I hi-light the node that created it. As soon as I click another node of even click somewhere else on the page, the entry in the sidebar disappears. It will come back if I click on the node and press the refress icon in the sidebar.

Is this expected behavior?

(I'm putting together example flows that might be good for the cookbook.)

0 Likes

#5

Yes, as the name "node context" implies the context is only valid for that node.

0 Likes