1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00
node-red/packages/node_modules/@node-red/nodes/examples/function/function/06 - Storing data in context.json
2020-06-24 14:43:27 +01:00

1 line
1.2 KiB
JSON

[{"id":"a3a635eb.191188","type":"inject","z":"97cd77e0.37c268","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":100,"wires":[["77f57d92.06fa14"]]},{"id":"1a218bea.61ae04","type":"debug","z":"97cd77e0.37c268","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":100,"wires":[]},{"id":"a56bde3a.330e1","type":"comment","z":"97cd77e0.37c268","name":"storing data in context","info":"The function node code can store data in the context store.\n\nSee Node-RED user guide about [functions](https://nodered.org/docs/user-guide/writing-functions) and [context store](https://nodered.org/docs/user-guide/context).","x":160,"y":40,"wires":[]},{"id":"77f57d92.06fa14","type":"function","z":"97cd77e0.37c268","name":"counter","func":"// initialise the counter to 0 if it doesn't exist already\nvar count = context.get('count')||0;\ncount += 1;\n// store the value back\ncontext.set('count',count);\n// make it part of the outgoing msg object\nmsg.payload = count;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":100,"wires":[["1a218bea.61ae04"]]}]