Node-RED

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.

 

Browser-based flow editing

 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.

Built on Node.js

 The flows created in Node-RED are stored using JSON which can be easily imported and exported for sharing with others.

Social Development

Workspace

Workspace UI

Node

A node can have at most one input port and many output ports.

Wire

Nodes are joined together by wires via their ports.

Subflows

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.

Importing and Exporting Flows

Flows can be imported and exported from the editor using their JSON format, making it very easy to share flows with others.

Core Nodes

Inject

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.

Debug

The Debug node can be used to display messages in the Debug sidebar within the editor.

Function

The Function node allows JavaScript code to be run against the messages that are passed through it.

 

Template

The Template node can be used to generate text using a message’s properties to fill out a template.

Change

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:

  • set
  • change
  • move
  • delete

 

Switch

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:

 

Initiate Flow

Creating your first flow

  • Once Node-RED is running, point a local browser at http://localhost:1880.

 

  • Use a browser from another machine if you know the ip address or name of the Node-RED instance - http://{Node-RED-machine-ip-address}:1880

1. Add an Inject node

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.

 

2. Add a Debug node

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.

3. Wire the two together

Connect the Inject and Debug nodes together by dragging between the output port of one to the input port of the other.

 

4. Add a Function node

The Function node allows you to pass each message though a JavaScript function.

5. Add HttpRequest

The HttpRequest node can be used to retrieve a web-page when triggered.

 

6. Add CSV

Add a CSV node and edit the properties, and tick the Input - [x] First row contains column names

 

7. Add Switch

  • 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

8. Add Change

  • Wire a Change node to the output of the Switch node.
  • Configure the node to Set, msg.payload to be PANIC!.

9. Deploy

Click the Deploy button. With the Debug sidebar tab selected, click the Inject button. You should see numbers appear in the sidebar.

 

Create a Node

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

Node-RED

By Sofwan Abdulwahab

Node-RED

  • 173