Node context not a function?

Have used context successfully for both global and flow. According to documentation, there is also node context. But can't get this to work and don't find any examples.

For example:

node.get("key");
node.set("key", msg.payload);

What am I missing?

That would be
context.set(path,value,store)
context.get(path,store)
https://nodered.org/docs/user-guide/writing-functions#context

1 Like

A simple example...

[{"id":"327c773e3f240405","type":"inject","z":"be4568a984cb4685","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":290,"y":2080,"wires":[["db2adbcefcbaa0d1"]]},{"id":"db2adbcefcbaa0d1","type":"function","z":"be4568a984cb4685","name":"function 7","func":"let storedCounter = context.get('count') || 0\nlet currentCounter = storedCounter + 1\ncontext.set('count', currentCounter)\nmsg.payload = currentCounter\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":2080,"wires":[["61ef5ffd74b3869d"]]},{"id":"61ef5ffd74b3869d","type":"debug","z":"be4568a984cb4685","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":2080,"wires":[]}]
1 Like

Thanks, somehow missed the API section (thought it was Rest api without looking).

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