- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
Node-RED provides a Function node that allows you to write custom JavaScript code to process messages flowing through your application. Below are some key features and examples of how to use functions effectively.
Basic Function Example
The simplest function processes the incoming message (msg) and returns it unchanged:
return msg;Copied!✕CopyIf you want to modify the message, you can update its properties:
msg.payload = "Hello, Node-RED!";return msg;Copied!✕CopyCreating New Messages
You can create a completely new message object:
var newMsg = { payload: msg.payload.length };return newMsg;Copied!✕CopyNote: If you create a new message, ensure you preserve required properties like msg.req and msg.res for HTTP flows.
Multiple Outputs
The Function node supports multiple outputs. You can send messages to specific outputs by returning an array:
if (msg.topic === "important") {return [msg, null]; // Send to first output} else {return [null, msg]; // Send to second output}Copied!✕CopyFor multiple messages on one output:
Writing Functions - Node-RED
Using the Node-Red Function Node- Beginners Guide
Node-RED Function Node Tutorial - Let's Automate!
Apr 23, 2023 · The Function Node in Node-RED provides immense flexibility and power for customizing automation flows. By harnessing JavaScript, you can …
Node-RED - Function Node • FlowFuse
Aug 5, 2024 · What Is a Function node in Node-RED? In Node-RED, a function node allows you to write custom JavaScript code to process message objects in your …
node-red.github.io/docs/user-guide/writing-functions.md at master ...
Before Node-RED 1.0, the Function node would not clone the first message passed to node.send, but would clone the rest. The Function can request the runtime to not clone the first message passed to …
Searches you might like
Node-RED Cheat Sheet - Function Node | vd Brink Home …
Show state icon It’s possible add a status icon under the function node and show a internal value next to it. In this case it shows a green round with value 0.
Understanding How to Use Node-RED Functions - InfluxData
Sep 27, 2023 · This post will define Node-RED functions and provide an example of how to use them in your flow. In addition, you’ll get a list of ways you can use Node …
Complete Node-red Tutorials 2024 - YouTube
Welcome to the ultimate Node-RED Tutorials 2024 playlist! Whether you're a beginner or looking to advance your skills, this series covers everything from Nod...
Node-RED Programming Guide
Then you’ll dive into how to program your own function nodes using JavaScript and create reusable sub flows to add your own functionality to the set of nodes …
Use an external JavaScript library in a Node-RED function
Jul 20, 2016 · More recent versions of Node-RED (v1.3.0 onward) have support for loading modules directly in the function node. The documentation have been updated to cover this.
Deep dive into Node Red Function Node JavaScript Tutorial