Programmatically remove unused config nodes

Hi, my scenario:

I have a set of nodes based on same core in same project
Now I want to split them to different projects for deploy
And I want still keep single project as source of such nodes
I was success to make a monster jsonata expression which takes nodes I want to keep and cut out all other and their childs using recursion, id, g , subflow:id and z attributes

But, there left config nodes and I can't get how to detect them in flows.json

So the questions -

May be there any easer way to programmatic export nodes from flows.json (like export ui does) ?
If not, how to detect config nodes for remove if no left node uses it ?

Are you looking for a solution from the editor or from the runtime?

From the editor:

You can use RED.nodes.eachNode or RED.nodes.eachConfig.

And into the node instance:

if (node._def.category === "config") {
  // it's a config node
  if (node.users.length === 0) {
    // config node not used
  }
}

I looking for solution from runtime, because I injecting it into CI pipeline, so when I building docker image I run node in automated mode, which generates splitted jsons.

Also node.js with running parts of node red would be better than I did.

So, there is no way to know that is a config node (unless you hard coded the types).

How editor know which ones ?

Presumably by using this information Configuration nodes : Node-RED. Probably by looking at the category.

1 Like

yeah, very disappointing solution, any plans to change this anyway ? It makes some inconviniences in my case :frowning: not fatal , but it would be really good to have it possible to make exports serverside in some common way.

The editor needs to know this is a config node because the editing box is different but the runtime just needs the type. So no.

Yes, I think it is flaw in flows arch, would be nice to have at least some common attribute shared between control nodes (even "control_node": true would help)

I forgot - you can check x and y: a config node does not have x and y properties.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.