How can my custom node have dynamic number of outputs?

Hi all.

I have tried searching and looking through node-red function and switch nodes but cant pin down how I can have 1 or 2 outputs depending on a users choice in a drop-down

For example, suppose I had an option on my custom node...

  • Throw errors (default)
  • Send errors in msg.error
  • Send errors to separate output

When a user chooses "Send errors to separate output" I'd like the node to change from having 1 output to having 2 outputs.

Any ideas?

Hi @Steve-Mcl

the trick is to add a property to your node's defaults object called outputs.

You can then modify this.outputs as you would any other node property. The editor knows to watch that property and update the node accordingly.

NIck

1 Like

Perfect - thank you