Node-RED is a flow-based programming tool, original developed by IBM’s Emerging Technology Services team and now a part of the JS Foundation.
Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range of nodes in the palette. Flows can be then deployed to the runtime in a single-click.
JavaScript functions can be created within the editor using a rich text editor.
The light-weight runtime is built on Node.js, taking full advantage of its event-driven, non-blocking model. This makes it ideal to run at the edge of the network on low-cost hardware such as the Raspberry Pi as well as in the cloud.
The flows created in Node-RED are stored using JSON which can be easily imported and exported for sharing with others.
Workspace UI
A node can have at most one input port and many output ports.
Nodes are joined together by wires via their ports.
A subflow is a collection of nodes that are collapsed into a single node in the workspace. Note: a subflow cannot contain an instance of itself - either directly or indirectly.
Flows can be imported and exported from the editor using their JSON format, making it very easy to share flows with others.
The Inject node can be used to manual trigger a flow by clicking the node’s button within the editor.
The message sent by the Inject node can have its payload and topic properties set.
The Debug node can be used to display messages in the Debug sidebar within the editor.
The Function node allows JavaScript code to be run against the messages that are passed through it.
The Template node can be used to generate text using a message’s properties to fill out a template.
The Change node can be used to modify a message’s properties and set context properties without having to resort to a Function node. The available operations are:
The Switch node allows messages to be routed to different branches of a flow by evaluating a set of rules against each message. There are four types of rule:
The Inject node allows you to inject messages into a flow, either by clicking the button on the node, or setting a time interval between injects.
The Debug node causes any message to be displayed in the Debug sidebar. By default, it just displays the payload of the message, but it is possible to display the entire message object.
Connect the Inject and Debug nodes together by dragging between the output port of one to the input port of the other.
The Function node allows you to pass each message though a JavaScript function.
The HttpRequest node can be used to retrieve a web-page when triggered.
Add a CSV node and edit the properties, and tick the Input - [x] First row contains column names
Wire a Switch node to the output of the CSV node.
Configure the property to be msg.payload.mag
Configure the test to be >= and the value to be 7
Click the Deploy button. With the Debug sidebar tab selected, click the Inject button. You should see numbers appear in the sidebar.
Required files to create a new node
A node’s properties are defined by the defaults object in its html definition. These are the properties that get passed to the node constructor function when an instance of the node is created in the runtime.
Node properties