How To Use Node-RED
During this lesson we are going to take a tour of the Node-RED editor and introduce you to some of the terminology used to describe the components. When you complete this lesson you will know your way around the editor when building your app.
Firstly, let’s look at nodes. Nodes are small packaged functions that perform a specific task. They take an input, perform a task and produce an output. When nodes are connected together in a chain they create a flow. We will look at flows later on, but for now, a flow is a group of nodes that are connected together to complete a task. The nodes live in the node palette on the left hand side of the editor. They are categorized into sections so that you can find the node you need easily and there is also a search function at the top.
A few basic nodes come pre-installed with Node-RED however, you can add more nodes by adding an Add-on.
Some nodes require configuration to use, to configure the node double-click on the node and it will open up a form like the inject node example below. Here you can configure the node with the settings you need.
RedConnect is a cloud hosted version of Node-RED. As we have mentioned a few basic nodes come pre-installed when you start your app. However, the true power of the platform is that you can add many nodes to connect to different systems. We call a collection of nodes an add-on. Normally, nodes are grouped in an add-on by the service or device they connect to. We have add-ons for many popular web services. For more information take a look at the add-on catalogue.
Creating a flow is simple, all you have to do is drag two or more nodes onto the sheet and then connect the dots found on the input or output of the node. When a node is triggered a message is passed from one node to the next from left to right until it reaches the end of the flow. In this example below we have an “inject” node sending the string “Hello!” to the debug node which is outputting the string in the debug panel. This is an incredibly simple flow and in later lessons we will explore much more powerful flows.
Tabs / Sheets
Sheets act as the workspace to create flows, they allow you to organise your flows into separate sheets so that you can easily navigate your app. We recommend that you create a single flow on each sheet so that you can easily find the flow. However, there is no reason why you could not create many flows on a single sheet. You can double-click the sheet name to rename it or delete it.
The debug panel is where the output from debug nodes is displayed. Often when building a flow it is useful to understand the output of a node that you are working on. By connecting the debug node to the output you can inspect the contents. The debug panel also displays any errors that are thrown during the flows life. If a flow is failing head to the debug panel to see if there is more information on the error.
The info panel gives you additional information about the node that is currently selected. Often this is where you find out how the node works and what input it is expecting. If the node needs some configuration such as API keys or authentication details then this information can be detailed here.
Subflows are used to create a reusable part of a flow, by converting a part of a flow into a node. Subflows can provide a way of reusing a part of a flow in other flows. To create a subflow you can highlight the nodes that you want to reuse and select “selection to subflow” from the menu. After the subflow is created it will appear in the node palette at the top so that you can drag it onto a sheet. Subflows can also abstract a flows complexity into a node allowing the flow to appear simpler at first glance.
We have learnt how to use the editor, in the next lesson we will take a deeper look at flows and how messages are passed from one node to another.