Running JavaScript against messages using a function node
You can run JavaScript against messages to perform various functions, e.g.:
- Modifying messages
- Creating new messages
- Handling errors
- Storing data
- Open Node-RED.
- Add a function node from the function category to the workspace.
- Double-click the function node to open the Edit node dialogue.
- In the Function text box, specify the JavaScript code.
- With the Outputs spinner, select the number of outputs.

The JavaScript code must return an array of messages to serve multiple outputs. If an element of that array is again an array of messages, multiple messages are send through the corresponding output.
- Click Done to apply your changes.
- Connect the input of the function node to the node that outputs the messages you want to run JavaScript against.