varandaas varandaas - 8 months ago 76
Node.js Question

Return one message for each output on Node-RED function block

In Node-RED, how do I return multiple messages on function blocks, one for each output?

I tried this based on documentation, with no success.

msg1 = "1"
msg2 = "2";
msg3 = "3";

msg.payload = [msg1, msg2, msg3];

return msg

Function block with 3 outputs


You need to return objects not just strings so firstly you need to build objects with payload keys

msg1 = {payload: "1"}
msg2 = {payload: "2"};
msg3 = {payload: "3"};

msg = [msg1, msg2, msg3];

return msg;