Search code examples
node.jsnode-red

Node red: share data between node


I am trying to share data between my node fucntions throw the use of context object, but seems like in this version it is not working:

My node version: 0.10.40
My node red version:  0.11.1

I can't update the node or the node red versions since I am using the embedded one in multitech mconduit gateway.. so I am stuck with this versions.

I tried the following context.set("AE", AE), I got TypeError: Object [object Object] has no method 'set'

and global.set('AE',AE), I got ReferenceError: global is not defined (line 7, col 1)

Any ideas how to share data between node in this old version?

Thanks, best regards,


Solution

  • For Node-RED that old there is only one type of context object (rather than the 3 seperate global, flow & context).

    The context object has no getter/setter methods and is just a simple JavaScript object, so you set values as follows:

    context.foo = "foo";
    

    and get values like this:

    var foo = context.foo;
    

    There is still the concept of the global context, this is now just a child object of the context e.g. context.global

    Check the yellow background boxes in the Node-RED documentation here