Skip to content

Keep a large flow readable ​

A flow on the line grows: cameras, models, rules, panels, error handling. Someone else will have to follow it, and so will you in six months. Node-RED has four tools to keep it readable: groups that frame the nodes of one task, comments that say what they do, link nodes that replace long wires, and subflows that fold a set of nodes into one. In this guide you tidy up a small inspection with all four.

What you will learn

  • How to group the nodes of one task and name the group
  • How to leave a comment for the next person
  • How to replace a long wire with link nodes
  • How to fold several nodes into a subflow

Before you start

Here a small inspection stands for a real one: «part detected» starts it, three function nodes take the picture, find the biscuits and count them, and a switch node far below gives the verdict, OK or NOK. The basics of the editor are in Introduction to Node-RED.

1. Group the nodes of one task ​

Drag on an empty part of the workspace to draw a box around «take picture», «find biscuits» and «count biscuits», which do one task together. Press Ctrl+Shift+G, or choose «Group selection» in the menu that opens with a right click. A frame appears around them, and moving the frame moves them all.

Group the nodes of one task

2. Name the group ​

Double-click the frame of the group and write its «Name», here «Take the picture and count». The same dialog sets the colour of the frame and of the name, to tell apart the parts of a flow at a glance: cameras, models, rules.

Name the group

3. Leave a comment ​

Click «Done». Drag a comment node above the group and open it. Its «Name» shows on the workspace, here «Counts the biscuits of each pack»; the text below it, in Markdown, shows in the information panel when someone selects the comment.

Leave a comment

4. Replace the long wire ​

Click «Done». Click the long wire from «count biscuits» down to «4 biscuits?» and press Delete. Drag a «link out» node after «count biscuits» and wire them; drag a «link in» node before «4 biscuits?» and wire it. Open the «link in» and name it «verdict»: that name is how the «link out» finds it.

Replace the long wire

Open the «link out» node. It lists the «link in» nodes of every flow: type verdict in its search box and tick it. A dotted line joins them while one of them is selected. A «link out» can also send to a «link in» on another tab, and a «link call» node calls a part of a flow and waits for its answer, like a function.

Connect the two link nodes

6. Check that it still works ​

Click «Done», deploy and press «part detected». The message goes through the group, jumps from «link out» to «verdict» and reaches «OK».

Check that it still works

7. Fold the group into a subflow ​

Click the frame of the group to select it. Open the main menu, at the top right, and choose «Subflows» and «Selection to Subflow». The three nodes become one node, an instance of a new subflow that also appears in the palette, under «subflows», ready to be used again in other flows. Double-click it and «Edit subflow template» to change what is inside, or name the instance, here «take and count».

Fold the group into a subflow

8. Run it once more ​

Deploy and press «part detected». The message goes through the subflow, the link and the verdict as before. A change to the subflow's template changes every instance of it.

Run it once more

Good to know ​

  • Find your way. The «Explorer» on the left lists every flow, group and node; the search box at its top, or Ctrl+F, finds a node by name, type or property.
  • One tab per part. Split a large flow into tabs (cameras, inspection, panel, communication) joined by link nodes, as the controller's demo flows do. A tab can be disabled as a whole to stop it without deleting it.
  • Subflow properties. A subflow can have properties of its own (its «Edit properties» tab), filled in on each instance: the same subflow then serves several cameras or models with different settings.
  • Notes on a node. Every node also has a «Description» tab in its dialog, in Markdown, shown in the information panel.

Next steps ​

Recorded on Rosepetal release 1.8.15, Node-RED 5.0.10.