You can easily create a flow in Node-RED by simply following the steps given below but before diving into How to create Flow in Node-RED we will first understand about Node and flow in Node-RED. For installation and tutorial of Node-RED click here.
What is a Node?
A Node can be considered as a basic building block. It is a block with at most 1 input port and many output ports. It can be added to workspace by either dragging from node palette or using quick-add dialogue or importing from clipboard/library. A node is joined together by wires via the port which forms a model or application. Nodes are well defined placed in various sections in node palette based on their function. You can add an additional node using npm. The common type of nodes is Inject node and Debug Node.
Node Properties
You can open the properties of a node by double-clicking on the node in the workspace. First, we will look at the properties of Inject node.
The Name attribute is the name given to the node in the workspace. Next is the (msg.) you can add additional (msg.anyname) by clicking on the add button and select the type from the dropdown list as shown. Moreover, you can assign a message to another message or any type like string, number, etc and enter its value. You can trigger the node by click or by setting an interval by selecting the type of interval from the dropdown as shown in the figure at right. You can enable and disable the node by clicking on the Enable/Disable button at the bottom right of the properties.
Now we will have a look at the properties of debug node. We can select the type of content to be displayed on the debug console using the Output Attribute. Moreover, we can select where to be displayed using To attribute. The Name attribute is the name given to the node in the workspace. Finally, we have and toggle button at the bottom right to enable and disable the node.
What is Flow?
A Flow is a wired connection of nodes to build applications and programs. In other words, it is a collection of nodes and wires. The blue block is the trigger node, it can be triggered either by clicking on the block or by setting an interval. The green block is the debug node, by default, it displays the payload of the message. Both the block are connected through a wire, which creates a flow
Flow Properties
You can open the Flow properties by Double clicking on the Flow tab at the top. Also you can add a new flow by double click at the side of the Flow tab
The Name Attribute value can be altered to change the name of the Flow Tab. You can add a description to the flow, it is useful when multiple people are working on the same project or when a new person needs to understand the flow. Finally, at the bottom right you have a toggle button to enable and disable the flow. You can also delete the flow by clicking on the delete button at the top left of properties or close the properties with changes by clicking on Done. You can also open the properties as shown below
Creating a Simple Flow
For creating your first simple flow follow the steps given below
- Drag and drop the inject node and debug node from the node palette available in common section to the workspace in the center. Then connect the node by clicking the output port of inject node and release the left click on the input port of debug node.
- Double click on the inject node to open its properties, give a name to the node of your choice, for now we select the the message type as string and enter a message and press Done once completed with configuration.
- Now you could see that the name of the node is changed to name entered in Name attribute, Message in my case. Next Double Click on the Debug node and select the output as msg. and enter the message name if not available by default. You can either select a single msg or complete msg object.
- Now Click on Deploy, You will get a pop-up saying successfully Deployed, then click on debug console present at the right and click on the trigger node. You will see the output in the debug console. Here you have successfully created your first flow. For more information click here.