# Programmatically remove unused config nodes

**URL:** <https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676>\
**Category:** General\
**Created:** [13 June 2024 17:08 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676 "2024-06-13T17:08:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [13 June 2024 17:08 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/1 "2024-06-13T17:08:40Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [13 June 2024 19:05 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/2 "2024-06-13T19:05:20Z")

</div>

> [@zba](#):
>
> Now I want to split them to different projects for deploy

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

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [13 June 2024 19:21 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/3 "2024-06-13T19:21:30Z")

</div>

From the editor:

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

And into the node instance:

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

```

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [13 June 2024 20:26 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/4 "2024-06-13T20:26:37Z")

</div>

> [@GogoVega](#):
>
> Are you looking for a solution from the editor or from the runtime?

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.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [13 June 2024 21:08 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/5 "2024-06-13T21:08:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [13 June 2024 21:21 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/6 "2024-06-13T21:21:48Z")

</div>

How editor know which ones ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 June 2024 07:48 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/7 "2024-06-14T07:48:50Z")

</div>

> [@zba](#):
>
> How editor know which ones

Presumably by using this information [Configuration nodes : Node-RED](https://nodered.org/docs/creating-nodes/config-nodes). Probably by looking at the category.

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [14 June 2024 11:45 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/8 "2024-06-14T11:45:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [14 June 2024 16:57 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/9 "2024-06-14T16:57:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [15 June 2024 03:11 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/10 "2024-06-15T03:11:08Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [15 June 2024 09:51 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/11 "2024-06-15T09:51:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 June 2024 09:51 UTC](https://discourse.nodered.org/t/programmatically-remove-unused-config-nodes/88676/12 "2024-06-29T09:51:57Z")

</div>

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