Node-RED Concepts
• Node
• Configuration node
• Flow
• Context
• Message
• Subflow
• Wire
• Palette
• Workspace
• Sidebar
Node
A Node is the basic building block of a flow.
Nodes are triggered by either receiving a message from the previous node in a
flow, or by waiting for some external event, such as an incoming HTTP request, a
timer or GPIO hardware change. They process that message, or event, and then
may send a message to the next nodes in the flow.
A node can have at most one input port and as many output ports as it requires.
• Working with Nodes
• The Core Nodes
• Creating Nodes
Configuration node
A Configuration (config) Node is a special type of node that holds reusable
configuration that can be shared by regular nodes in a flow.
For example, the MQTT In and Out nodes use an MQTT Broker config node to
represent a shared connection to an MQTT broker.
Config nodes do not appear in the main workspace, but can be seen by opening
the Configuration nodes sidebar.
• Working with Configuration nodes
• Configuration node sidebar
Flow
A Flow is represented as a tab within the editor workspace and is the main way
to organise nodes.
The term “flow” is also used to informally describe a single set of connected
nodes. So a flow (tab) can contain multiple flows (sets of connected nodes).
• Working with Flows
Context
Context is a way to store information that can be shared between nodes without
using the messages that pass through a flow.
There are three types of context;
• Node - only visible to the node that set the value
• Flow - visible to all nodes on the same flow (or tab in the editor)
• Global - visible to all nodes
By default, Node-RED uses an in-memory Context store so values do not get
saved across restarts. It can be configured to use a file-system based store to
make the values persistent. It is also possible to plug-in alternative storage
plugins.
• Working with context
• Context Store API
Message
Messages are what pass between the nodes in a flow. They are plain JavaScript
objects that can have any set of properties. They are often referred to
as msg within the editor.
By convention, they have a payload property containing the most useful
information.
• Working with messages
Subflow
A Subflow is a collection of nodes that are collapsed into a single node in the
workspace.
They can be used to reduce some visual complexity of a flow, or to package up a
group of nodes as a reusable component used in multiple places.
• Working with Subflows
Wire
Wires connect the nodes and represent how messages pass through the flow.
• Working with Wires
Palette
The Palette is on the left of the editor and lists of the nodes that are available to
use in flows.
Extra nodes can be installed into the palette using either the command-line or the
Palette Manager.
• Working with the Palette
• Adding nodes to the palette
• The Palette Manager
Workspace
The Workspace is the main area where flows are developed by dragging nodes
from the palette and wiring them together.
The workspace has a row of tabs along the top; one for each flow and any
subflows that have been opened.
• Working with the Workspace
Sidebar
The sidebar contains panels that provide a number of useful tools within the
editor. These include panels to view more information and help about a node, to
view debug message and to view the flow’s configuration nodes.
• Working with the Sidebar
Running on Raspberry Pi
Prerequisites
If you are using Raspbian, then you must have Raspbian Jessie as a minimum version.
Raspbian Buster is the currently supported version.
Installing Node-RED
We provide a script to install [Link], npm and Node-RED onto a Raspberry Pi. The
script can also be used to upgrade an existing install when a new release is available.
Running the following command will download and run the script. If you want to review
the contents of the script first, you can view it.
bash <(curl -sL [Link]
installers/master/deb/update-nodejs-and-nodered)
This script will:
• remove the pre-packaged version of Node-RED and [Link] if they are present
• install the current [Link] LTS release using the NodeSource. If it detects
[Link] is already installed from NodeSource, it will ensure it is at least Node 8,
but otherwise leave it alone
• install the latest version of Node-RED using npm
• optionally install a collection of useful Pi-specific nodes
• setup Node-RED to run as a service and provide a set of commands to work with
the service
Running locally
As with running Node-RED locally, you can use the node-red command to run Node-
RED in a terminal. It can then be stopped by pressing Ctrl-C or by closing the terminal
window.
Due to the limited memory of the Raspberry Pi, you will need to start Node-RED with an
additional argument to tell the underlying [Link] process to free up unused memory
sooner than it would otherwise.
To do this, you should use the alternative node-red-pi command and pass in the max-
old-space-size argument.
node-red-pi --max-old-space-size=256
Running as a service
The install script for the Pi also sets it up to run as a service. This means it can run in
the background and be enabled to automatically start on boot.
The following commands are provided to work with the service:
• node-red-start - this starts the Node-RED service and displays its log output.
Pressing Ctrl-C or closing the window does not stop the service; it keeps
running in the background
• node-red-stop - this stops the Node-RED service
• node-red-restart - this stops and restarts the Node-RED service
• node-red-log - this displays the log output of the service
You can also start the Node-RED service on the Raspbian Desktop by selecting
the Menu -> Programming -> Node-RED menu option.
Autostart on boot
If you want Node-RED to run when the Pi is turned on, or re-booted, you can enable the
service to autostart by running the command:
sudo systemctl enable [Link]
To disable the service, run the command:
sudo systemctl disable [Link]
Opening the editor
Once Node-RED is running you can access the editor in a browser.
If you are using the browser on the Pi desktop, you can open the
address: [Link]
When browsing from another machine you should use the hostname or IP-address of
the Pi: [Link] You can find the IP address by running hostname -
I on the Pi.