How can I set the error indicator (little red triangle) of a node in the editor?

It is true to say the runtime apis for these types of actions are far more limited - simply because Nodes generally do not have a need to do these things. And none of the nodes that have 'hacked' around the available APIs have ever discussed any possible API changes or improvements.

The editor provides better APIs because it is more generally useful to be able to do these things when editing the flow.

Everything that follows only applies in the editor. This is no equivalent in the runtime.

Finding by name

There's no direct way to find anything by its 'name' - names are optional fields and can be left blank. They are also not unique. Under the covers you should be using the id field to reference other nodes.

let node = RED.nodes.node(id);

To get any nodes whose name property is set to a particular value:

let results = [];
RED.nodes.eachNode(function(node) {
   if (node.name === "HELLO") {
      results.push(node);
   }
});

(If you dig around the code, you'll see RED.nodes.filterNodes exists - that currently only filters on z and type rather than any other property... but it would be simply enough to update to handle any property... we have never needed it)

The above works for regular flow nodes. To do the same for Config nodes or Flows, you'd do the same but with eachConfig() and eachWorkspace() respectively.

Find connected nodes of a given node

let node = RED.nodes.node(nodeId);
let allConnectedNodes = RED.nodes.getAllFlowNodes(node)

If you just want the nodes that come 'before' or 'after' this one, you can do:

let allUpstreamNodes = RED.nodes.getAllUpstreamNodes(node);
let getAllDownstreamNodes = RED.nodes.getAllDownstreamNodes(node)
1 Like