Nodes and Flows

Nodes are the basic building blocks of a flow. Depending on its type, a node can receive an input, generate an output, or both. The output port of one node is connected to the input port of the next node in the flow. A node is triggered (instructions configured into the node are executed) after receiving a message flow from the previous node or an external event, such as sensor data from a serial input or a timer. The node processes the message received and then may send a message to the next node in the flow. A node can have at most one input port and as many output ports as it requires.

The messages are simple JavaScript objects that can have any set of properties. They usually contain a message-id (auto inserted by Node-RED), payload, and topic. The payload property holds the primary data of the node that intends to pass to the next node. The payload can be simple text, numbers, or JSON objects.

{
  _msgid: "12345.67890",  
  topic: "HomeCentral/Temperature",
  payload: {"value": 22,"unit": "Celcius" }
}

There are three broad types of nodes:

  • Input Nodes

    Input nodes allow you to input data into a Node-RED flow. You use input nodes to receive data from external components, such as sensors via the serial port input, or services such as email or Twitter, or via manual methods.

  • Output Nodes

    Output Nodes allow you to output data to the debug console or outside of the Node-RED flow. You use output nodes to send data to a database for storage, a controller to manage a device, or a service such as an email or Twitter to send an alert.

  • Processing Nodes

    Processing Nodes allow you to process data. They provide standard functionality that lets you transform the data from one format to another or use the data to trigger a message conditionally. You can also write custom code to process the data received.

Some nodes have a button that allows you to trigger them manually (for an inject node) or enable/disable a node (in the case of the debug node). Clicking on the trigger button for an inject node will send a configured message to the next node in the flow. Clicking on the enable/disable button will do just that, enable or disable the node. Inject and Debug are exclusive input and output nodes, but some other services may offer both (for example, you can receive a message from an MQTT input node and publish it from an MQTT output node).

Configuring Nodes

Every node can be configured according to the required parameters depending on what type of node it is. For example, an inject node can be configured with payload data and should be repeated over a particular time interval. An MQTT output node will need to be configured with the broker details, including the URL, port, access credentials, and a topic to publish or subscribe to. Drag and drop the node you need in the flow and then double click on it to see the configuration parameters for the node. Node-RED flows are created by placing nodes on the Flow panel and connecting them by drawing a line between the outputs of one node to the input of another node. The small square on the left of a node is its input, and the right is its output. Thus, in a flow, data moves from left to right. Input nodes only have an output connection as they expect their input through an external source. Output nodes only have an input connection as they send their output to an external destination. Function nodes have both connections as they may receive input from another node and send it out to another node. For services that can act as an input or an output, there will be two nodes. For example, there will be a Twitter input node and a separate Twitter output node.