# Avoiding cloning messages

**URL:** <https://discourse.nodered.org/t/avoiding-cloning-messages/24808>\
**Category:** General\
**Created:** [14 April 2020 12:35 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808 "2020-04-14T12:35:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![thiagorizzo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thiagorizzo/32/19962_2.png) [@thiagorizzo](https://discourse.nodered.org/u/thiagorizzo)\
**Post date:** [14 April 2020 12:35 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/1 "2020-04-14T12:35:42Z")

</div>

Hi all,

I just read [Cloning messages in a flow](https://nodered.org/blog/2019/09/13/cloning-messages). Whats the best pratice on flat flows to avoid message cloning? should I code functions this way:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0c362c3e49d0e04705e6daa93f54ab15d966a886.png)

Thank you!

---

<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:** [14 April 2020 12:42 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/2 "2020-04-14T12:42:08Z")

</div>

You are right - to send a message without it being cloned, use `node.send(msg, false)`.

This _only_ stops it cloning the message to the first node it is wired to. If it is wired to multiple nodes, then the 2nd (and subsequent) nodes _will_ receive a clone of the message object.

---

<div class="post-metadata">

**Author:** ![thiagorizzo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thiagorizzo/32/19962_2.png) [@thiagorizzo](https://discourse.nodered.org/u/thiagorizzo)\
**Post date:** [14 April 2020 12:43 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/3 "2020-04-14T12:43:53Z")

</div>

Thank you @knolleary.

---

<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 April 2020 12:58 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/4 "2020-04-14T12:58:28Z")

</div>

> [@knolleary](#):
>
> to send a message without it being cloned, use `node.send(msg, false)`

Is there a difference between that and `return msg`? I thought that also doesn't clone if there is only one output wired.

---

<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:** [14 April 2020 13:10 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/5 "2020-04-14T13:10:01Z")

</div>

Yes, you are right - I had to double check because the blog post doesn't explicitly say so.

`return msg` will _not_ clone the message passed to the first wired node.

---

<div class="post-metadata">

**Author:** ![thiagorizzo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thiagorizzo/32/19962_2.png) [@thiagorizzo](https://discourse.nodered.org/u/thiagorizzo)\
**Post date:** [14 April 2020 13:32 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/6 "2020-04-14T13:32:18Z")

</div>

so, theres no difference between both methods?

```auto
node.send(msg, false);
return null;

```

and

`return msg;`

---

<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 April 2020 14:23 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/7 "2020-04-14T14:23:44Z")

</div>

Correct, no difference. The purpose of `node.send(msg, false)` is for where you need to use `node.send()`, which _does_ clone by default, but don't want it to clone. Often when using `node.send` you do want it to clone in order to avoid sending the same message multiple times, which can cause problems, as if a later node changes the message contents then that would change the original msg that then may get sent again.

---

<div class="post-metadata">

**Author:** ![thiagorizzo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thiagorizzo/32/19962_2.png) [@thiagorizzo](https://discourse.nodered.org/u/thiagorizzo)\
**Post date:** [14 April 2020 14:26 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/8 "2020-04-14T14:26:50Z")

</div>

Thanks @Colin. 😄

---

<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:** [28 April 2020 14:33 UTC](https://discourse.nodered.org/t/avoiding-cloning-messages/24808/9 "2020-04-28T14:33:06Z")

</div>

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