The Node-RED palette includes a default set of nodes that are the basic building blocks for creating flows. This page highlights the core set you should know about.
All nodes include documentation you can see in the Info sidebar tab when you select a node.
The Inject node can be used to manual trigger a flow by clicking the node’s button within the editor. It can also be used to automatically trigger flows at regular intervals.
The message sent by the Inject node can have its payload
and topic
properties
set.
The payload
can be set to a variety of different types:
The interval
can be set up to a maximum of 596 hours (approximately 24 days).
If you are looking at intervals greater than one day - consider using a scheduler node that can cope with power outages and restarts.
The interval between times
and at a specific time
options use the standard cron system. This means that 20 minutes will be at the next hour, 20 minutes past and 40 minutes past - not in 20 minutes time. If you want every 20 minutes from now - use the interval
option.
Since Node-RED 1.1.0, the Inject node can now set any property on the message.
The Debug node can be used to display messages in the Debug sidebar within the editor.
The sidebar provides a structured view of the messages it is sent, making it easier to explore the message.
Alongside each message, the debug sidebar includes information about the time the message was received and which Debug node sent it. Clicking on the source node id will reveal that node within the workspace.
The button on the node can be used to enable or disable its output. It is recommended to disable or remove any Debug nodes that are not being used.
The node can also be configured to send all messages to the runtime log, or to send short (32 characters) to the status text under the debug node.
The page on Working with messages gives more information about using the Debug sidebar.
The Function node allows JavaScript code to be run against the messages that are passed through it.
A complete guide for using the Function node is available here.
The Change node can be used to modify a message’s properties and set context properties without having to resort to a Function node.
Each node can be configured with multiple operations that are applied in order. The available operations are:
When setting a property, the value can also be the result of a JSONata expression. JSONata is a declarative query and transformation language for JSON data.
The Switch node allows messages to be routed to different branches of a flow by evaluating a set of rules against each message.
The node is configured with the property to test - which can be either a message property or a context property.
There are four types of rule:
true
value.The node will route a message to all outputs corresponding to matching rules. But it can also be configured to stop evaluating rules when it finds one that matches.
The Template node can be used to generate text using a message’s properties to fill out a template.
It uses the Mustache templating language to generate the result.
For example, a template of:
This is the payload: {{payload}} !
Will replace {{payload}}
with the value of the message’s payload
property.
By default, Mustache will replace certain characters with their HTML escape codes.
To stop that happening, you can use triple braces: {{{payload}}}
.
Mustache supports simple loops on lists. For example, if msg.payload
contains
an array of names, such as: ["Nick", "Dave", "Claire"]
, the following template
will create an HTML list of the names:
<ul>
{{#payload}}
<li>{{.}}</li>
{{/payload}}
</ul>
<ul>
<li>Nick</li>
<li>Dave</li>
<li>Claire</li>
</ul>
The node will set the configured message or context property with the result of the template. If the template generates valid JSON or YAML content, it can be configured to parse the result to the corresponding JavaScript Object.
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy