Multiple Outputs: Banana

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Multiple Outputs

The function edit dialog allows the number of outputs to be changed. If there is more
than one output, an array of messages can be returned by the function to send to the
outputs.

This makes it easy to write a function that sends the message to different outputs
depending on some condition. For example, this function would send anything on
topic banana to the second output rather than the first:

if (msg.topic === "banana") {


return [ null, msg ];
} else {
return [ msg, null ];
}

The following example passes the original message as-is on the first output and a
message containing the payload length is passed to the second output:

var newMsg = { payload: msg.payload.length };


return [msg, newMsg];

You might also like