Add More User-Friendly Way to Add Outputs to Function Node

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];


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 :slight_smile:

Topic moved to Feature Requests, as it’s not a discussion around custom node development.

How would you remove an output once created?

I do think function outputs are problematical because you must have as many outputs declared as messages that [may] be emitted.

This is valid code:

let newmsg = []
const words = msg.payload.split(" ")
for (let i in words) {
    newmsg.push ( {payload:{num: i, word: words[i]}})
return newmsg;

msg.payload can be an arbitrarily long sentence and the function will create a new message for each word, but if the node has 5 outputs, words 6 onwards get silently dropped.

I know node.send is available to handle an unknown number of output messages but I think throwing away messages without even a warning is bad.

Can't deny that a warning would probably be sensible.

One minor point though, you don't need node.send to send multiple messages, you can return them just as well. As long as you return an array within an array: return [ newmsg ] would send a stream of msgs in your example (I think I got that the right way round).

I would recommend new users to refrain from function nodes as long as they can, many things can be done with the standard change/switch nodes.

Although I could see the configuration of the number of outputs directly in the "On message" tab, I am not sure if this is such a big deal, you set it up once right ?

Dear Bakman

Although I am a beginning node-red user,
I am an experienced programmer for 30+ years.
And I known when a UI could be improved.

It took me quit some time to figure out how to increase the amount of outputs.
All the forums assume you know where to adjust it.
But are unclear where exactly, like path of buttons to press or a simple screenshot.
Its obvious when you know and you will never forget, but it should not be such a pain to figure it out.
The tab where the input and outputs can be named, has already an x to remove an output.
It would be an obvious place to have also a + button.

Many nodes offer useful features, but tend to fail in my edge cases.
Also debugging is a pain, and I almost would advise, first code your function node code in a development IDE for JavaScript and then copy it in.

Anyway, its not for me I am asking,
But to reduce the barrier for any new user.

Greets John van der Pol

It is not about the outputs generated.

But the configuration of additional outputs
I scan an image an based on what is detected a message is send to either
PersonDetected, AnimalDetected, or CarDetected nodes
I figured out that i could send multiple outputs, but it took me a hell of a lot of time to know how I could increase the amount of outputs.
Removing one in the configuration is easy, hit the x behind it in the configuration screen.
But adding one is not possible on that tab, you need to go to the first tab and there is an option amount of outputs.
a simple + or add button on the tab where you can name the outputs would save for alot of beginners hours of searching.

Dear TotallyInformation.

Actually I did need to use the node.send.
Because I use the fetch to make a call to CodeProjectAI to scan my image.
This is an async call. And I actually do not want to (a)wait on the result.
The node ends before it processed the image.
It would return a empty sets. (Also took me some time to notice this).

Using the node.send it now it sends for each element of interest a call to the respective sub node, starting like a sub flow.

Anyway as mentioned already.
the problem is not to be able to send an array of messages, or even an array of array of messages.
The problem was to define the amount of outputs, which could be easily be adjusted to be more intuitive for a beginning node red user.

If you mean the x button on the appearance tab, it does not delete the output, it just deletes it's name, which is pretty inexplicable.
To delete an output you have to go to the setup tab of the properties tab and decrement the "Outputs" field.
So currently you do add and remove outputs in the same place.

It's far from clear to me how/why that works but yes it does!

I think it would be bad form to use that to send a bunch of messages out of the same output, but then I think it's bad form to send a single message out of output 4 with return [ null, null, null, newmsg, null ] yet not everyone agrees. :thinking:

Hi jBudd,

Its all besides the point.
What I try to say is, that I could figure out how I could make really complex returns.
The only thing I had a lot of problems with, was to find where in the function node I could configure that it had three outputs.
The GUI design can be made more clearly, as stated on several posts.

Greets John van der Pol

Please note that you are not the only "experienced" programmer here. If there is one thing I have learned from the development cycle of node-red: changes usually have been very clearly considered, discussed, contemplated and reasoned. That is not to say that this is one of them, then again, you could be very experienced with programming, but not necessarily with node-red. You could also just send out your message and use a switch node to route it for example.

@john_wpg I appreciate your points and to some degree I too think the number of outputs would be better suited alongside the naming of outputs. I also appreciate you raising this and taking the time to request improvements - thanks.

However, as @bakman2 has alluded to, there are considerations to be understood.

Firstly, the appearance TAB is a common form across all nodes. This means in order to have "setup stuff" on that form specifically for the function node would be an exception. Sure, it could be dynamically handled but once you consider that each node has the exact same "appearance" and "description" tabs you must realise that node specific settings (e.g. "setting the number of outputs") will be somewhere else? Perhaps this is just a docs + experience thing?

In the case of the function node docs, as you state, they are not 100% clear where this setting is. But the beauty of node-red is that everything is open source (including the docs) and pull requests to the docs are most welcome :wink:

Even the built in help could be more "helpful" again, being open source, these can be improved too.

Moving forward: with the afore mentioned in mind, if you can think of a sensible alternative, I am certain it would be considered.

Kind regards, Steve.

Just to put this into context, while the docs are indeed open for PR's, even the main docs aren't especially easy for "outsiders" to get their heads around. I've not managed to watch all of Nick's videos but maybe doing a documentation pull request would be a good one to add if it hasn't already been.

As for updating the node's help panel, this is probably beyond most people because even finding the code to change is no easy task due to the complex structure of the repo and the fairly complex structure of the nodes. Again, that might also make a good video tutorial?

We all want more people to get involved but we need to remember that for the majority of Node-RED users, these tasks, which seem simple for "insiders" appear like quantum mechanics to others.

Further to my previous post, I would like to point out that the links I provided will take you to the exact place in the source code where the modifications discussed would be required (as Julian said, it is not always obvious where things go)

Dear Steve-MCI, Bakman2

Its not that I am proposing for a move of the amount of output options to the place where the outputs are named.
Just a plus button to add extra outputs, close to the place where to define the output name to remove one .
I have seen a plus button used in node-red for some other options, but do not remember in which form.
Its where you would expect it.
It would make the UI consistent.
Its not for me I am asking, but for the community.
I will never forget the place anymore where I can increase the amount of outputs.

Greets John van der Pol

Hi @john_wpg

In earlier versions of Node-RED, the outputs control was on the same tab as the code itself. That made it much more visible, but it also used up valuable screen space that took away from the space available for the code.

As Steve mentioned, the appearance tab is a common tab for all nodes - it doesn't know that the number of outputs is configurable for any particular node.

But I do agree there would be some sense to having the output count sit alongside the output labels. It's just a bit tricky to achieve. We don't want to hardcoded Function node logic into the common appearance tab.

We can infer that the output count is variable from the presence of an outputs property, however that doesn't mean the user should be able to directly set it like the function node. The Switch node can have a variable number if outputs, but that is determined by the number of rules added to the node.

So, thank you for the feedback. It is something for us to look at, just know its a bit trickier to achieve than just moving the setting for the one node type.

1 Like

Hi @knolleary

Again, thanks for the feedback.
I am not rooting for a move of the output count, but for a simple + button so you can add a new output in the appearance tab.
There is already a X to delete one, just not a + to add one.

Greets John van der Pol

No there isn't. As has been explained earlier in the thread, that is related to adding/removing the labels of the outputs. It doesn't change the number of outputs.

That is understood and my reply was an attempt to explain why "a simple + button" isn't actually a simple change.

In my humble opinion there are only 4 tabs to look at in order to find out where to add more outputs.

Given that setup is the first tab and appropriately named, it all seems perfectly logical as it is now.

I think it may just need a simple mention of this tab in the docs ?