# Multiple objects returned by a single node

**URL:** <https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021>\
**Category:** General\
**Created:** [16 October 2018 06:09 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021 "2018-10-16T06:09:34Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hc\_IoT](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hc\_IoT](https://discourse.nodered.org/u/Hc_IoT)\
**Post date:** [16 October 2018 06:09 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/1 "2018-10-16T06:09:34Z")

</div>

Hi Bart,

I was trying to use a node created by you named as "node-red-contrib-cpu" and it returns multiple objects at a time. What I was trying to do is to fetch payload value from each object and merge it into a single JS object or display each msg object individually. But I didn't succeed and I am not able to find any example related to that on google, so can you please help me on that.

Here's the link for the flow: [https://drive.google.com/open?id=1tAygTMr-lDNczhOjv8t80Sh3h8pRQDqM](https://drive.google.com/open?id=1tAygTMr-lDNczhOjv8t80Sh3h8pRQDqM)

@BartButenaers

---

<div class="post-metadata">

**Author:** ![Hc\_IoT](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hc\_IoT](https://discourse.nodered.org/u/Hc_IoT)\
**Post date:** [16 October 2018 06:42 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/2 "2018-10-16T06:42:33Z")

</div>

Hi,

I have just found a **solution** to my problem by using a switch node and comparing the msg.topic value to a particular string (core\_1, core\_2 and so on).  
I am attaching the link to my flow code in case someone wants to try this or looking for a solution for this node. Here you go:  
[https://drive.google.com/open?id=19oXR\_3k\_\_TYlTsTJKTDAdliHXoQuZef2](https://drive.google.com/open?id=19oXR_3k__TYlTsTJKTDAdliHXoQuZef2)  
Sorry for the drive links, I will soon upload all my flow codes to github for easy access to all.

@BartButenaers , if you know any other better solution to this then please do share for people like me.  
I would like to suggest you to please include few examples for your node on any platform like github, [nodered.org](http://nodered.org) or any other where you would like to. It will be a much help to better understand this node.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [16 October 2018 11:04 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/3 "2018-10-16T11:04:59Z")

</div>

Hello Harshit,

> [@Hc\_IoT](#):
>
> it returns multiple objects at a time

I have no access to Node-RED at the moment, so I cannot try your example at the moment.  
You can [choose](https://www.npmjs.com/package/node-red-contrib-cpu#output-message-for-each-core) whether you want 1 message containing the info of all cores, OR 1 message for each core separately. So I assume you have selected _'Output message for each core'_ and then you want to merge all those messages together into a single message. Isn't it easier that you let the node output a single message?

Bart

---

<div class="post-metadata">

**Author:** ![Hc\_IoT](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hc\_IoT](https://discourse.nodered.org/u/Hc_IoT)\
**Post date:** [17 October 2018 04:44 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/4 "2018-10-17T04:44:40Z")

</div>

Hi Bart,

Thanks for sharing the documentation link but I have gone through it already and as you can see I got the desired output.

> [@BartButenaers](#):
>
> Isn't it easier that you let the node output a single message?

Yes, it is but what if you want to see performance for each individual cores for a system with multiple cores. I am assuming that you are referring to [this method](https://www.npmjs.com/package/node-red-contrib-cpu#output-message-for-overall-cpu-usage).

I have also posted my example/ use-case to the github. Here is the [link](https://github.com/harshitc/node-red-examples/tree/master/node-red-contrib-cpu_example) for that.

Hc

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [17 October 2018 19:23 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/5 "2018-10-17T19:23:43Z")

</div>

Evening Harshit,

It is some time ago that I wrote that cpu-node, and it indeed seems that you cannot have a **single** output message containing the information of **all** cpu's. I had completely forgotten that I haver added such an option... I'm getting old 😩

Currently for each core you will get a message like this (with payload containing the usage percentage):  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1ab18dbee0eca928533c0b55acf2c000512d47ed.png)

I could add a new option to the config screen:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0dd0434b298c16fc36c38093008407b7bf59a79f.png)

But how should the corresponding output message need to look like?  
Perhaps a **msg.topic = "all\_cores"** and **msg.payload** containing an array like this:

```auto
[
    {
        "name": "core_1",
        "usage": 7,
        "model": "ARMv7 Processor rev 4 (v71)",
        "speed": 600
    },
    {
        "name": "core_2",
        "usage": 43,
        "model": "ARMv7 Processor rev 4 (v71)",
        "speed": 600
    },
   ...
]

```

Does anybody have a better idea ?

Bart

---

<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:** [17 October 2018 21:11 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/6 "2018-10-17T21:11:00Z")

</div>

I would reverse the order of the three options :-)... and make the new one mention the word array... "Create a single array of..."

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [17 October 2018 21:25 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/7 "2018-10-17T21:25:35Z")

</div>

Dave, that is weird.  
Asked my wife an hour ago for feedback, and she had the same kind of response (about order, color, text ...).  
But she didn't mentioned a word about the wonderfull developments behind the checkbox.  
The both of you must have something in common 😂.  
So it would become something like this:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f1871347c548140b60334b48ef50aa85105448be.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [17 October 2018 21:38 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/8 "2018-10-17T21:38:59Z")

</div>

Just to wordsmith it a bit more... Personally I found it confusing if they all start “Create a message”

My suggestion would be ...

Create a message for overall usage

Create a separate message for each core usage

Create a single message containing an array of core usages

---

<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:** [17 October 2018 21:54 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/9 "2018-10-17T21:54:07Z")

</div>

I would also suggest that nodes 'send messages' rather than 'create messages'

---

<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:** [17 October 2018 22:22 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/10 "2018-10-17T22:22:48Z")

</div>

And are they really tick boxes ? Can they all be selected ? Should it not be a select box ?

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [17 October 2018 22:31 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/11 "2018-10-17T22:31:34Z")

</div>

> [@knolleary](#):
>
> I would also suggest that nodes 'send messages' rather than 'create messages'

Deal ...

> [@dceejay](#):
>
> And are they really tick boxes

Yes, on NPM there are already tick boxes. So a bit tricky if I change it to a dropdown now, to break existing flows ...

You could indeed select them all at once, which perhaps makes no sense in most cases. But that is not really a problem since each tickbox provides its own dedicated **topics** to the corresponding messages. For example:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a766583f0c9f0df9bd4df71d0433307cf6305047.png)

---

<div class="post-metadata">

**Author:** ![Hc\_IoT](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hc\_IoT](https://discourse.nodered.org/u/Hc_IoT)\
**Post date:** [18 October 2018 04:20 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/12 "2018-10-18T04:20:24Z")

</div>

Though being an amateur in this area what all I can say is, this looks good and will serve the purpose very well.  
And thanks for making the efforts to create this node 🙂

Hc

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [18 October 2018 20:31 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/13 "2018-10-18T20:31:19Z")

</div>

Hello Harshit,

I have a added a new ( **0.0.3** ) version on Github, that contains the new checkbox.  
If it looks like what you had in mind, please let me know so I can publish it on NPM !!  
Meanwhile you can install this test version directly from Github via command line:

```auto
npm install bartbutenaers/node-red-contrib-cpu

```

All changes in a nutshell:

- A section about new option has been added to the [readme](https://github.com/bartbutenaers/node-red-contrib-cpu/blob/master/README.md) page. And for all 3 available options, message examples have been added.

- The node's config screen has been updated. And the help in the info panel has also been extended:  

- The new checkbox will generate an array of information for all cpu's. In the next screenshot you will see the comparison to the existing '_send a separate message for each core usage_' option:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6847e0e6356ee73ab988681f5702f3f3ef5eb814.png)

Thanks guys for all the feedback !!  
Bart

---

<div class="post-metadata">

**Author:** ![Hc\_IoT](https://avatars.discourse-cdn.com/v4/letter/h/a5b964/32.png) [@Hc\_IoT](https://discourse.nodered.org/u/Hc_IoT)\
**Post date:** [19 October 2018 06:28 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/14 "2018-10-19T06:28:34Z")

</div>

Hi Bart,

I have gone through the new option and tested it on localhost as well as on an AWS instance and it indeed served the purpose. I would like to say thank you for putting all the efforts for creating this option.

Hc

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [19 October 2018 22:17 UTC](https://discourse.nodered.org/t/multiple-objects-returned-by-a-single-node/4021/15 "2018-10-19T22:17:17Z")

</div>

Hi Harshit,

You are welcome! Thank you for testing the change!  
I have published it on NPM, and the new **0.0.3** version is now available in the Node-RED palette:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/eb5bb4c4b7c484144b330a15ad4ad5605c8d1adc.png)

Kind regards,  
Bart
