Subflows in Node-RED

Subflows in Node-RED are a powerful feature that enables users to group a set of nodes into a single, reusable component. This functionality is particularly beneficial for several reasons:

Modularity

Subflows allow for the creation of modular components within Node-RED flows. By encapsulating nodes that perform a specific function into a subflow, it becomes easy to reuse this functionality across different parts of your application or in multiple projects without the need to duplicate the nodes.

Simplification

Complex flows can become challenging to manage and understand. Organizing related nodes into subflows simplifies the main flow, enhancing readability and maintainability. The main flow thus focuses on high-level logic, while the detailed implementations are contained within the subflows.

Customization

Subflows can be equipped with their own set of environment variables or input parameters, enabling the creation of flexible components. These components can be adjusted based on their usage context without modifying the internal logic of the subflow.

Sharing and Collaboration

Subflows facilitate easy sharing of a useful set of nodes, either within the Node-RED community or across projects in an organization. This promotes collaboration and the dissemination of best practices.

In essence, subflows in Node-RED serve to encapsulate, simplify, and reuse groups of nodes. They contribute to organizing complex flows into a more manageable and modular structure, allowing for customization and fostering collaboration.

How to Create Subflows

To create a subflow, click on the icon with three horizontal lines located in the top right corner of the interface and choose the Create Subflow option from the menu.

  1. Once you select Create Subflow, a new subflow instance will be displayed in the toolbar. Double-click on this instance to access its configuration panel. In the configuration panel, you can assign a name to your subflow and manage environmental variables. Add new variables by clicking the + Add button.

create subflow
  1. Additional configuration options are available under the "Edit Properties" section. Here, you can adjust the number of input and output ports for the subflow by selecting from the available options.

edit properties subflows