# Number of nodes

**URL:** https://discourse.nodered.org/t/number-of-nodes/95046
**Category:** General
**Created:** [1 February 2025 14:02 UTC](https://discourse.nodered.org/t/number-of-nodes/95046 "2025-02-01T14:02:19Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [1 February 2025 14:02 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/1 "2025-02-01T14:02:19Z")

</div>

Hi,

this is the list of nodes of a flow ...

 ![img](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af2a04077a342ca57b0cf97877ed9f263526415e.png)

can I know the number of the node? Or the number of node in (all) my project?

It's a simple curiosity ....

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [1 February 2025 14:20 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/2 "2025-02-01T14:20:10Z")

</div>

Here is a little flow to count the number of nodes in all flows, by node type.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d534d97824afebc6342456794f1a5cd4442ef3c4.png)

```auto
[{"id":"1918a51fd4dc2e4a","type":"group","z":"3378d78bb37c052e","name":"Counting nodes in flows.json all at once","style":{"label":true},"nodes":["02cf87c8d1cf30c1","6aa2c90239f6b087","ccd47e52b8a3a5c5","6800dfd62b817b01","d81b083e0d1de79e"],"x":14,"y":159,"w":832,"h":82},{"id":"02cf87c8d1cf30c1","type":"inject","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":200,"wires":[["6aa2c90239f6b087"]]},{"id":"6aa2c90239f6b087","type":"file in","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"flows.json","filename":".node-red/flows.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":260,"y":200,"wires":[["ccd47e52b8a3a5c5"]]},{"id":"ccd47e52b8a3a5c5","type":"json","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"","property":"payload","action":"","pretty":false,"x":410,"y":200,"wires":[["d81b083e0d1de79e"]]},{"id":"6800dfd62b817b01","type":"debug","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"Show","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":200,"wires":[]},{"id":"d81b083e0d1de79e","type":"change","z":"3378d78bb37c052e","g":"1918a51fd4dc2e4a","name":"Count","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload { type: $count($) }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":200,"wires":[["6800dfd62b817b01"]]}]

```

---

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [1 February 2025 14:38 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/3 "2025-02-01T14:38:18Z")

</div>

Ok, thank you ...

---

<div class="post-metadata">

### Author: ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)
#### Post date: [1 February 2025 15:25 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/4 "2025-02-01T15:25:52Z")

</div>

@Giamma You should accept the solution by clicking the "Solved" checkbox.

---

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [1 February 2025 17:42 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/5 "2025-02-01T17:42:57Z")

</div>

With sort by type and total sum (code by ChatGPT)

```auto
[{"id":"02cf87c8d1cf30c1","type":"inject","z":"01760d4e9f96f88b","name":"go","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":1780,"wires":[["6aa2c90239f6b087"]]},{"id":"6aa2c90239f6b087","type":"file in","z":"01760d4e9f96f88b","name":"flows.json","filename":".node-red/flows.json","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":320,"y":1780,"wires":[["ccd47e52b8a3a5c5"]]},{"id":"ccd47e52b8a3a5c5","type":"json","z":"01760d4e9f96f88b","name":"","property":"payload","action":"","pretty":false,"x":450,"y":1780,"wires":[["d81b083e0d1de79e"]]},{"id":"6800dfd62b817b01","type":"debug","z":"01760d4e9f96f88b","name":"Show","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":1780,"wires":[]},{"id":"d81b083e0d1de79e","type":"change","z":"01760d4e9f96f88b","name":"Count","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload { type: $count($) }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":1780,"wires":[["32c2180ed0fa9198","1938bf898cce916b"]]},{"id":"32c2180ed0fa9198","type":"function","z":"01760d4e9f96f88b","name":"function 16","func":"const output = [null];\n\nlet data = msg.payload;\nlet sortedKeys = Object.keys(data).sort();\n\nlet sortedObj = {};\nsortedKeys.forEach(key => {\n sortedObj[key] = data[key];\n});\n\noutput[0] = { payload: sortedObj }\n\nreturn output;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":1780,"wires":[["6800dfd62b817b01"]]},{"id":"1938bf898cce916b","type":"function","z":"01760d4e9f96f88b","name":"function 15","func":"const output = [null];\n\nlet data = msg.payload;\nlet sum = 0;\nfor (let key in data) {\n if (data.hasOwnProperty(key)) {\n sum += data[key];\n }\n}\n\noutput[0] = { payload: sum };\n\nreturn output;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":1820,"wires":[["dabbc05ded7e6e42"]]},{"id":"dabbc05ded7e6e42","type":"debug","z":"01760d4e9f96f88b","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":900,"y":1820,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 February 2025 18:23 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/6 "2025-02-01T18:23:59Z")

</div>

Or the whole thing in one change node, giving you a total count and ordering the type.

```auto
$merge(
    [
        {"total_nodes":$count($$.payload)},
        $$.payload^(type){type:$count($)}
    ]
)

```

---

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [1 February 2025 19:19 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/7 "2025-02-01T19:19:35Z")

</div>

Ok, I prefer yours, thank you ....

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [1 February 2025 20:09 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/8 "2025-02-01T20:09:45Z")

</div>

> [@E1cid](#):
>
> ```auto
> $merge(
> [
> {"total_nodes":$count($.payload)},
> $$.payload^(type){type:$count($)}
> ]
> )
> 
> ```

That's an excellent example of grouping and subtotalling with Jsonata, thanks @E1cid.  
Single and double dollars, round and squiggly brackets, carets, functions ...

It's gradually becoming nearly as intuitive as regular expressions!

---

<div class="post-metadata">

### Author: ![PizzaProgram](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pizzaprogram/32/19431_2.png) [@PizzaProgram](https://discourse.nodered.org/u/PizzaProgram)
#### Post date: [2 February 2025 15:43 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/9 "2025-02-02T15:43:30Z")

</div>

> [@E1cid](#):
>
> ```auto
> $merge(
> [
> {"total_nodes":$count($.payload)},
> $.payload^(type){type:$count($)}
> ]
> )
> 
> ```

This should go to [FAQ](https://nodered.org/docs/faq/) + Flow examples.

---

<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: [16 February 2025 15:43 UTC](https://discourse.nodered.org/t/number-of-nodes/95046/10 "2025-02-16T15:43:52Z")

</div>

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