Why is sendEvents an array (in the Messaging hooks)

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

Perhaps I am misinterpreting the documentation 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

The description of the onSend event explains here: Messaging Hooks : Node-RED

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.

1 Like

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.

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