Subflows

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 flow used in multiple places.

Once created, the subflow is added to the palette of available nodes. Individual instances of the subflow can then be added to the workspace just like any other node.

Note: a subflow cannot contain an instance of itself - either directly or indirectly.

Creating an empty subflow

A subflow can be created by selecting the ‘Subflow -> Create subflow’ option in the menu. This will create a blank subflow and open it in the workspace.

Reference
Key shortcutnone
Menu optionSubflows -> Create subflow
Actioncore:create-subflow

Converting nodes to a subflow

It is also possible to convert the current selection of nodes to a subflow by selecting the ‘Subflow -> Selection to Subflow’ option in the menu. The nodes will be moved to a new subflow and replaced by a subflow instance node within the flow.

Creating a subflow

Creating a subflow

Invalid subflow selection

Invalid subflow selection

This is only possible if any wires coming into the selection are connected to one node - as the resulting subflow node can itself only have at most one input.


Reference
Key shortcutnone
Menu optionSubflows -> Selection to Subflow
Actioncore:convert-to-subflow

Editing a subflow

There are two ways to open a subflow to edit its contents. Either double click its node in the palette, or click the ‘Edit flow template’ button in the edit dialog of a subflow instance node.

The subflow is opened in the workspace as a new tab. Unlike regular flow tabs, subflow tabs can be closed to hide them.

Editing a subflow

Editing a subflow

Inputs & Outputs

The inputs and outputs of the subflow are represented by the grey square nodes that can be wired into the flow as normal.

The toolbar provides options to add and remove these nodes. As with normal flows nodes, there can be at most one input and as many outputs as needed.

Status node

The toolbar provides an option to add a ‘status’ output to a subflow. This can be used to update the Status of subflow instance nodes. The node uses the input of msg.payload which can either be a simple string or a Status Object

Editing subflow properties

The ‘edit properties’ button opens the subflow properties dialog. As with the Flow properties dialog, the name and description of the subflow can be set.

  • : Properties - per-instance properties that are exposed as environment variables within the subflow.
  • : Module Properties - metadata about the subflow. Since Node-RED 1.3
  • : Description - per-node documentation formatted using Markdown. This is displayed in the Information sidebar when the node is selected.
  • : Appearance - options to customise the appearance of the node.
Subflow edit dialog - properties Subflow edit dialog - module properties Subflow edit dialog - description Subflow edit dialog - appearance

Subflow edit dialog - properties, module properties, description and appearance tabs

Properties
Editing subflow properties

Editing subflow properties

Editing subflow property UI

Editing subflow property UI

The ‘Properties’ tab of the edit dialog can be used to define a set of properties that can then be customised for each instance of the subflow. The properties are then exposed as environment variables within the subflow.

Each entry in the properties table can be expanded to customise how it is displayed when an instance of the subflow is edited. The ‘UI Preview’ tab provides a preview of how they will appear.


Module Properties

The Module Properties tab can be used to set additional meta-data about the Subflow, including version, license and module name. These can be used when packaging the Subflow as an npm module.

Appearance

The Appearance tab provides options to:

  • change the palette category the node appears in
  • select whether the node’s label is shown
  • change the colour of the node
  • change the icon of the node
  • provide custom port labels.

Deleting a subflow

The ‘delete subflow’ button in the subflow toolbar can be used to remove the subflow and all instances of it.