# Multiple send(msg) in custom nodes

**URL:** <https://discourse.nodered.org/t/multiple-send-msg-in-custom-nodes/66437>\
**Category:** Developing Nodes\
**Created:** [15 August 2022 10:50 UTC](https://discourse.nodered.org/t/multiple-send-msg-in-custom-nodes/66437 "2022-08-15T10:50:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [15 August 2022 10:50 UTC](https://discourse.nodered.org/t/multiple-send-msg-in-custom-nodes/66437/1 "2022-08-15T10:50:04Z")

</div>

Hi,  
Sorry if a repost (please point me in case this was already discusses)

I am developing a custom node which needs to do multiple sends from within its input handler. I see a difference between custom & function nodes:

In a function node, if I use node.send(msg) multiple times, it will send separate msg instances. For example:  
`msg.payload = "AAA"`  
`node.send(msg)`  
`msg.payload = "BBB"`  
`node.send(msg)`  
=\> will send the payloads AAA, BBB as intended.

However in a custom node, the runtime seems to send twice the same msg instance (in its latest state). For example:

`node.on('input', function(msg, send, done) {`  
` msg.payload = "AAA"`  
` send(msg)`  
` msg.payload = "BBB"`  
` send(msg)`  
` done()`  
`});`  
=\> will send BBB, BBB.

Is this is because the runtime defers the actual sending, hence 1st msg is impacted by the modification for the 2nd send?

I can work around this by creating new msg instances (let msg2 = {payload:"BBB"} etc.), but just wanted to know if I should be doing something else.

Thanks!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 August 2022 11:15 UTC](https://discourse.nodered.org/t/multiple-send-msg-in-custom-nodes/66437/2 "2022-08-15T11:15:58Z")

</div>

> [@omrid](#):
>
> Is this is because the runtime defers the actual sending, hence 1st msg is impacted by the modification for the 2nd send?

in a roundabout way, yes.

read here: [Cloning messages in a flow : Node-RED](https://nodered.org/blog/2019/09/13/cloning-messages) - section **Cloning by default**

> ### Cloning by default
> 
> With Node-RED 1.0, when a Function node calls `node.send()`, it will now clone every single message, including the first. This will ensure code like that above will continue to work.

Have a read of that page.

NOTE: Typically, the user will expect the original msg properties in the output of your node - it is up to you as a node designer to decide what cloning is necessary.

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [15 August 2022 11:33 UTC](https://discourse.nodered.org/t/multiple-send-msg-in-custom-nodes/66437/3 "2022-08-15T11:33:38Z")

</div>

Thanks Steve!

---

<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:** [14 October 2022 11:34 UTC](https://discourse.nodered.org/t/multiple-send-msg-in-custom-nodes/66437/4 "2022-10-14T11:34:02Z")

</div>

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