Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. 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!

    If you want to modify the message, you can update its properties:

    msg.payload = "Hello, Node-RED!";
    return msg;
    Copied!

    Creating New Messages

    You can create a completely new message object:

    var newMsg = { payload: msg.payload.length };
    return newMsg;
    Copied!

    Note: 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!

    For multiple messages on one output:

    Feedback
  2. Writing Functions - Node-RED

    The code entered into the Function node represents the bodyof the function.The most simple function simply returns the message exactly as-is: If the function returns null, th…
    Multiple Outputs

    The function edit dialog allows the number of outputs to be changed. If thereis more than one output, an array of messages can be returned by the function tosend to the outputs. This makes it easy to write a function that sends the message to differ…

    Multiple Messages

    A function can return multiple messages on an output by returning an array ofmessages within the returned array. When multiple messages are returned for anoutput, subsequent nodes will receive the messages one at a time in the orderthey …

    Sending Messages Asynchronously

    If the function needs to perform an asynchronous action before sending a messageit cannot return the message at the end of the function. Instead, it must make use of the node.send()function, passing in the message(s)to be sent. It ta…

  3. Using the Node-Red Function Node- Beginners Guide

    • See More

    Jan 20, 2025 · The function node is used to run JavaScript code against the msg object. The function node accepts a msg object as input and can return 0 or more message objects as output.

    • 4.3/5
    • Ratings: 6
    • Reviews: 6
  4. 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 …

  5. 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 …

    Missing:
    • Tutorial
    Must include:
  6. 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 …

  7. Searches you might like

  8. 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.

  9. 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 …

  10. 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...

  11. 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 …

  12. 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.