How to send payload for each iteration (function node) a payload to MQTT node?

hello firends,
this is my function:

var LastCommands = msg.payload.split('\n')
global.set("LastCommands", LastCommands);
LastCommands.forEach(function(command) {
   // send each "command" with 250ms delay to MQTT node
});

How can I send a msg.payload for each iteration in the loop to an other node (MQTT) ?
Thx !

See the docs

https://nodered.org/docs/user-guide/writing-functions#multiple-messages
https://nodered.org/docs/user-guide/writing-functions#sending-messages-asynchronously

1 Like

or instead - use a split node (that will emit one msg per line (\n) - then a delay node in rate limit mode set to 250mS

thx!
I made it like this:

var LastCommands = msg.payload.split('\n')
global.set("LastCommands", LastCommands);
LastCommands.forEach(function(command) {
   node.send({payload:command});
});

...plus random delay node