# Node.on('input', function(msg, send, done) - what is send for?

**URL:** <https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988>\
**Category:** Developing Nodes\
**Created:** [25 June 2020 17:05 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988 "2020-06-25T17:05:16Z")\
**Posts on this page:** 15\
**Page:** 1

<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:** [25 June 2020 17:05 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/1 "2020-06-25T17:05:16Z")

</div>

The new prototype for receiving a message in a node is, I believe,  
`node.on('input', function(msg, send, done) {`  
I can't find any documentation or examples showing what `send` is for. Can someone elucidate, or point me to the docs please?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [25 June 2020 17:19 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/2 "2020-06-25T17:19:47Z")

</div>

`send` is the send function that's otherwise reachable through `this.send()`. It is now passed as argument to the input function, I'm looking up the announcement for it as I type.

> **[Knowing when a node is done](https://nodered.org/blog/2019/09/20/node-done)**
>
> There's a new callback function signature for handling messages in Node-RED 1.0. If you've created your own nodes, find out what's changing, what to update and how to stay backwards compatible.

> [@](#):
>
> The `send` function is a drop-in replacement for `node.send()` . The key difference is that when its called, the runtime will be able to correlate it back to the original `msg` object that was received.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [25 June 2020 19:30 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/3 "2020-06-25T19:30:28Z")

</div>

Don't forget to add a test and a dummy definition if you need to cater to non-v1 uses.

---

<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:** [25 June 2020 19:58 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/4 "2020-06-25T19:58:28Z")

</div>

Excellent, thanks for that. I see it is also documented where it should be [1] but not in as full detail as in the blog. I had looked there but missed it.

Where it says "The key difference is that when it's called [send], the runtime will be able to correlate it back to the original `msg` object that was received", having correlated it back what does it do with that information?

[1] [https://nodered.org/docs/creating-nodes/node-js](https://nodered.org/docs/creating-nodes/node-js)

---

<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:** [25 June 2020 19:58 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/5 "2020-06-25T19:58:52Z")

</div>

> [@TotallyInformation](#):
>
> Don't forget to add a test and a dummy definition

Yes, I had got that bit, thanks.

---

<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:** [25 June 2020 20:00 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/6 "2020-06-25T20:00:32Z")

</div>

> [@Colin](#):
>
> Where it says "The key difference is that when it's called [send], the runtime will be able to correlate it back to the original `msg` object that was received", having correlated it back what does it do with that information?

Today - absolutely nothing.

But in the future it will allow for a better level of metric logging and traceability of messages through flows.

---

<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:** [25 June 2020 20:21 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/7 "2020-06-25T20:21:29Z")

</div>

OK, thanks. Now, back to the code ...

---

<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:** [25 June 2020 20:43 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/8 "2020-06-25T20:43:54Z")

</div>

When I call `done(error)` then a Catch node picks it up, but I don't get a Complete event. Is that correct? I had expected to get the error then a complete event.

---

<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:** [25 June 2020 20:45 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/9 "2020-06-25T20:45:57Z")

</div>

That is correct. It gives a clear separation of flows for success and failure. If you want to trigger something regardless of success or failure, then you can add both nodes and wire them to same next node.

---

<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:** [25 June 2020 20:46 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/10 "2020-06-25T20:46:48Z")

</div>

Is it not valid for a node to generate more than one error event then?

---

<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:** [25 June 2020 21:04 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/11 "2020-06-25T21:04:57Z")

</div>

The node can call node.error as much as it likes.

But it can only call done(error) once for a message when it has finished with it.

---

<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:** [25 June 2020 21:16 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/12 "2020-06-25T21:16:45Z")

</div>

But in that case the user can't tell when it has finished, as you don't know whether there is another error coming. Unless the final error is marked as such in some way. That is ok though, I can do that.

---

<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:** [25 June 2020 21:24 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/13 "2020-06-25T21:24:18Z")

</div>

A node should make it clear to the user what they can expect.

In most cases, if a node encounters an error that warrants triggering the catch node, then that will end it's processing of the message.

It will only be for specific types of node that it might log multiple errors for a given message - certainly not the norm.

I can't remember if we already add a flag to the error if recorded with done(error). My laptop is asleep and so soon will I be.

---

<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:** [26 June 2020 09:25 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/14 "2020-06-26T09:25:51Z")

</div>

> [@knolleary](#):
>
> A node should make it clear to the user what they can expect.

Certainly, that is arguably the most important point.

> [@knolleary](#):
>
> I can't remember if we already add a flag to the error if recorded with done(error).

I don't think so, I can't see it anyway.

I have some further questions related to this but rather than have the thread head even further off topic I have [started a new one](https://discourse.nodered.org/t/how-would-exec-node-be-designed-now/29020) with some specific questions.

---

<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:** [25 August 2020 09:25 UTC](https://discourse.nodered.org/t/node-on-input-function-msg-send-done-what-is-send-for/28988/15 "2020-08-25T09:25:56Z")

</div>

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