Where do I find docs for RED.nodes.createNode/getNode/eachNode/

Trying to build my own Node-RED nodes, I looked for any documentation on

  • RED.nodes.createNode()
  • RED.nodes.getNode()
  • RED.nodes.eachNode()
  • RED.nodes.originaFlow()

On stackoverflow, I've been told that now such docs would exist and I should open a discourse topic for this question.

Ok, here it is: could anybody please explain syntax and semantics of the functions mentioned above?

Thanks in advance for any response!

Hi @rozek

  • RED.nodes.createNode() is called from your node's constructor function as detailed here: JavaScript file : Node-RED - there isn't a lot else to say about it.

  • RED.nodes.getNode(id) is a runtime function that gets ahold of another node instance. The typical use is where you have a configuration node that is shared by other nodes. They would use getNode to get ahold of the config node and access its properties.

  • RED.nodes.eachNode(function callback(node) { }) is a runtime function that will call the provided callback for each active node in the current flow configuration. In general nodes should not need to use this.

  • RED.nodes.originaFlow() - I don't know what that is. I don't recognise it as anything in our source code.

Thank you very much for this first explanation.

But what is an "active node in the current flow configuration"? Are there "active" and "passive" nodes? And "flow configuration" is just the full set of nodes and their wires?

by the way, I made a typo: RED.nodes.originaFlow() must actually be RED.nodes.originalFlow(). It is used by node-red-contrib-components, but not set there which is why I assumed it would be part of Node-RED itself

Ah yes. I did look for originalFlow (which exists internally) but I didn't realise it had been exposed to nodes in the API.

It returns the current flow JSON - exactly what appears in the flow file.

It is all the nodes running in the flow. It will include all of the internal instance nodes from any subflows.