# Why is sendEvents an array (in the Messaging hooks)

**URL:** <https://discourse.nodered.org/t/why-is-sendevents-an-array-in-the-messaging-hooks/54293>\
**Category:** Developing Nodes\
**Tags:** hooks\
**Created:** [25 November 2021 22:22 UTC](https://discourse.nodered.org/t/why-is-sendevents-an-array-in-the-messaging-hooks/54293 "2021-11-25T22:22:41Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [25 November 2021 22:22 UTC](https://discourse.nodered.org/t/why-is-sendevents-an-array-in-the-messaging-hooks/54293/1 "2021-11-25T22:22:41Z")

</div>

Hi folks,

From the time that Nick announced the Messaging hooks framework, my fingers have been itching to experiment with it. So fascinating stuff. But unfortunately I never had time for it ...

Started my first experiment tonight, but I am a bit confused.  
While the onReceiveEvent is a plain object, the onSendEvent seems to be an array:

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

Perhaps I am misinterpreting the [documentation](https://nodered.org/docs/api/hooks/messaging/#sendevent-object) incorrectly, but that looks to me also like a single plain object.

Might this be related to the case where a node has multiple outputs or something like that?

Thanks!!  
Bart

---

<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:** [26 November 2021 00:15 UTC](https://discourse.nodered.org/t/why-is-sendevents-an-array-in-the-messaging-hooks/54293/2 "2021-11-26T00:15:50Z")

</div>

The description of the `onSend` event explains here: [Messaging Hooks : Node-RED](https://nodered.org/docs/api/hooks/messaging/#onsend)

> The hook is passed an array of `SendEvent` objects. The messages inside these objects are exactly what the node has passed to `node.send` - meaning there could be duplicate references to the same message object.

In other words, a single call to `node.send()` might contain multiple messages, and will trigger a single `onSend` event with all of those messages provided in the array of SendEvent objects.

---

<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:** [26 November 2021 07:02 UTC](https://discourse.nodered.org/t/why-is-sendevents-an-array-in-the-messaging-hooks/54293/3 "2021-11-26T07:02:18Z")

</div>

Ok thanks Nick! That is clear.  
I was first confused because there where no square brackets in the json example. But of course that shows the content of a single event object... And I had overlooked that part in the written documentation, which indeed explains it very well.

---

<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:** [10 December 2021 07:02 UTC](https://discourse.nodered.org/t/why-is-sendevents-an-array-in-the-messaging-hooks/54293/4 "2021-12-10T07:02:20Z")

</div>

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