# Search for orphan nodes

**URL:** <https://discourse.nodered.org/t/search-for-orphan-nodes/77783>\
**Category:** General\
**Created:** [21 April 2023 09:22 UTC](https://discourse.nodered.org/t/search-for-orphan-nodes/77783 "2023-04-21T09:22:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 April 2023 09:22 UTC](https://discourse.nodered.org/t/search-for-orphan-nodes/77783/1 "2023-04-21T09:22:28Z")

</div>

Hi Folks!

I was wondering there there is a search term for `input:0 output:0` i.e. nodes that have zero connections in and zero connections out, i.e. orphan nodes. I don't mean the nodes definition but the nodes usage in a flow.

There is a very specific reason why this is relevant for me and my use of Node-RED - this isn't an everyday use-case.

Is there a search reference guide which could give me more details?

Cheers!

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [21 April 2023 09:33 UTC](https://discourse.nodered.org/t/search-for-orphan-nodes/77783/2 "2023-04-21T09:33:30Z")

</div>

Not by default. But the Node-RED linter nrlint may have a rule for that. I’ve not checked.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [21 April 2023 09:36 UTC](https://discourse.nodered.org/t/search-for-orphan-nodes/77783/3 "2023-04-21T09:36:46Z")

</div>

No, the search functionality doesn't extend to filtering based on the connections a node has.

If you open the JavaScript console in the browser, you could run the following code to get such a list of nodes - it's a little raw, but does the job,

```auto
const connectedNodes = new Set()
const disconnectedNodes = new Set()
// Iterate over all links, add the nodes to the 'connected' set
RED.nodes.eachLink(link => { connectedNodes.add(link.source); connectedNodes.add(link.target) })
// Iterate over all nodes, add any not in the connected set to the disconnected set
RED.nodes.eachNode(node => { if (!connectedNodes.has(node)) disconnectedNodes.add(node) })
// Loop over and print out node info
disconnectedNodes.forEach(n => console.log(n.id, n.type, n.name))

```

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 April 2023 09:49 UTC](https://discourse.nodered.org/t/search-for-orphan-nodes/77783/4 "2023-04-21T09:49:37Z")

</div>

> [@knolleary](#):
>
> ```auto
> const connectedNodes = new Set()
> const disconnectedNodes = new Set()
> // Iterate over all links, add the nodes to the 'connected' set
> RED.nodes.eachLink(link => { connectedNodes.add(link.source); connectedNodes.add(link.target) })
> // Iterate over all nodes, add any not in the connected set to the disconnected set
> RED.nodes.eachNode(node => { if (!connectedNodes.has(node)) disconnectedNodes.add(node) })
> // Loop over and print out node info
> disconnectedNodes.forEach(n => console.log(n.id, n.type, n.name))
> 
> ```

Thank you 👍

I'll make myself a node that generates a list similar to a link-in/out node so that I can highlight these nodes or a modified debug node that generates debug messages upon which I can click. Or better still, just extend the search window 😉

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 April 2023 13:14 UTC](https://discourse.nodered.org/t/search-for-orphan-nodes/77783/5 "2023-04-21T13:14:27Z")

</div>

I ended up creating an extra node for displaying orphans nodes. It's similar to link-in/out in that it shows the nodes in the tray view --\> [node code](https://gist.github.com/gorenje/bbf6f4f27553b864a0fc4dcc63d12ae2)

The node then shows a list of all nodes that match the [search criteria](https://gist.github.com/gorenje/bbf6f4f27553b864a0fc4dcc63d12ae2#file-95-orphans-html-L78-L84) using the treeList. When a entry gets clicked on, the workspace (i.e. tab) is changed to the nodes workspace and the node is brought into focus, much as search does. What I'd like to know is whether the [code](https://gist.github.com/gorenje/bbf6f4f27553b864a0fc4dcc63d12ae2#file-95-orphans-html-L66-L70) for that refocus is ok?

I ended up digging around in the Node-RED source code and found the `view.reveal` and `workspace.show` - I assume I can use those directly 🙂

---

<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:** [5 May 2023 13:14 UTC](https://discourse.nodered.org/t/search-for-orphan-nodes/77783/6 "2023-05-05T13:14:42Z")

</div>

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