Hi folks,
Feels like I'm developing my first function node...
I created a simple function node that counts the input messages:
[{"id":"ec7fdd88.78f28","type":"function","z":"5a89baed.89e9c4","name":"msg counter","func":"// First time initialization\nif (!this.msgCounter) {\n this.msgCounter = 0;\n}\n\nthis.msgCounter = this.msgCounter + 1;\n//node.msgCounter++;\n\nmsg.msgCounter = this.msgCounter;\nreturn msg;","outputs":1,"noerr":0,"x":590,"y":160,"wires":[["ff8f2dc7.37996"]]},{"id":"33e53ca0.90be34","type":"inject","z":"5a89baed.89e9c4","name":"Inject msg","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":420,"y":160,"wires":[["ec7fdd88.78f28"]]},{"id":"ff8f2dc7.37996","type":"debug","z":"5a89baed.89e9c4","name":"Show output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"msgCounter","x":770,"y":160,"wires":[]}]
And that works fine: the counter increments for every message. Otherwise I would have stopped developing in Node-RED right away
However in the function module I store the counter value in this.msgCounter:
this.msgCounter = this.msgCounter + 1;
So I don't store the counter on the node context memory, as I normally do. But when I try to find the function node, based on it's node id:
var test = RED.nodes.getNode("ec7fdd88.78f28");
Then I get an instance of the function node without 'msgCounter' property:
Can anybody explain this? And does anybody know a solution to get the instance that has the 'msgCounter' property?
Thanks !!
Bart