I have been using Node-RED for a project and found that adding additional outputs to a Function node can be a bit confusing. Currently, users need to go to the properties tab to add additional outputs, which can be time-consuming and not very intuitive.
I would like to suggest a more user-friendly way to add outputs to the Function node. Specifically, I think it would be helpful to have a + button next to the existing output connections that allows users to easily add an additional output. This would save time and make the process of adding outputs more intuitive.
I believe this would be a useful feature for many Node-RED users, especially those who are new to the platform. Thank you for considering my suggestion.
The whole conversation:)
How can I increase the number of outputs on a function node, and how can I return multiple msg objects.
By default, a Function node in Node-RED has a single input and a single output. However, you can configure a Function node to have multiple outputs by adding more output connections.
To add additional outputs to a Function node, you can click on the small circle on the right side of the node and drag it to create a new output connection. You can create as many output connections as you need.
To return multiple msg
objects from a Function node, you can create an array of msg
objects and call node.send()
with the array. Here's an example:
cssCopy code
var msg1 = { payload: "Message 1" };
var msg2 = { payload: "Message 2" };
var msg3 = { payload: "Message 3" };
var msgs = [msg1, msg2, msg3];
node.send(msgs);
In this example, we define three msg
objects (msg1
, msg2
, and msg3
) and add them to an array called msgs
. We then call node.send()
with the msgs
array to send all three messages at once. Each output connection of the Function node will receive one message from the array in order. So if there are three output connections, msg1
will be sent to the first output, msg2
to the second, and msg3
to the third.
To add additional outputs to a Function node, you can click on the small circle on the right side of the node and drag it to create a new output connection. You can create as many output connections as you need. I tried that, but it adds all to the same small circle. Is there some configuration i need to set?
You don't need to set any special configuration to add multiple output connections to a Function node in Node-RED. You should be able to create new output connections by clicking and dragging on the small circles on the right side of the node.
If you're having trouble creating separate output connections, make sure you click and drag on the circles themselves, rather than on the lines connecting them. It can also be helpful to zoom in on the node to make the circles easier to click on.
Once you have created multiple output connections, you can use the node.send([msg1, msg2, ...])
method in your Function node to send multiple message objects out of different output connections. The messages should be contained in an array, with one element for each output connection.
For example, the following code in a Function node sends two messages out of different output connections:
cssCopy code
var msg1 = { payload: 'message 1' };
var msg2 = { payload: 'message 2' };
node.send([msg1, null, msg2]);
In this example, msg1
is sent out of the first output connection, msg2
is sent out of the third output connection, and the second output connection is left empty by passing null
in the array.
Yeah, I figured that all out too, just picking your brain. However to add additional outputs in a function node. You need to go to its properties, and in the setup tab, you can increase the number of outputs. On the left side of that form there is an appearance icon, here you can name the individual outputs. It would have been nice if one could have a + button here to add one output more (there is an x to delete them), instead of losing a day looking for the solution on another tab.
You are correct, to increase the number of outputs in a Function node, you need to go to the "Setup" tab in the node's properties and increase the number of outputs there. Once you have done that, you can click on the "Appearance" tab to name the individual outputs.
It is true that adding a + button to add more outputs directly in the Appearance tab could be more intuitive, and it may be worth suggesting this as a feature request to the Node-RED team. In the meantime, I'm glad you were able to find the solution to your problem.
Can you make a detailed request for this feature, so i can post it on the node red forum.
Can you also add instructions on how to make this request and where?
And here it is