Section 1: Node-RED Basics
In this section, readers will understand what a flow-based programming (FBP) tool is, including Node-RED, along with how to undertake IoT/web programming with it, and will learn how to use the Node-RED flow editor at a basic level.
In this section, we will cover the following chapters:
- Chapter 1, Introducing Node-RED and Flow-Based Programming
- Chapter 2, Setting Up the Development Environment
- Chapter 3, Understanding Node-RED Characteristics by Creating Basic Flows
- Chapter 4, Learning the Major Nodes
Chapter 1: Introducing Node-RED and Flow-Based Programming
This chapter will help you grow from being a reader to being a Node-RED user. First, you'll learn about the history of Flow-based programming (FBP) tools, not just Node-RED. You will then gain a broad understanding of the entirety of Node-RED as a useful tool for building web applications and the Internet of Things (IoT) data handling, before learning what IoT and Node.js are in terms of Node-RED.
Providing technical content will help accelerate your software application development, but if you take a look at the history of the Node-RED tool itself, it will help you better understand why you need a FBP tool such as Node-RED. That is what we will be doing in this chapter.
More specifically, we'll be covering the following topics:
- What is FBP?
- What is Node-RED?
- Node-RED benefits
- Node-RED and IoT
Let's get started!
What is FBP?
So, what is FBP in the first place? It's the workflows you use in your work that you can easily imagine. Let's recall those workflows.
Workflows
In a normal workflow, boxes and wires indicate the process flow. It may be just one business design. Boxes represent processes. Box processing is defined by who, when, where, what, and how much. Sometimes, it's like explicitly writing out the flow of processing, such as by using swim lanes or placing writing definitions inside boxes. In any case, looking at the box should reveal what will be done.
On the other hand, let's try to summarize this business process as a document. Don't you think it will be complicated? Who will do what as they read it, even if they use some paragraphs well to put it together? When will you do it? It could be confusing:
Figure 1.1 – Workflow example
Now, let's get back to software programming. FBP is a kind of concept for software programming that defines an application with a data flow. Each part of the process is there as a black box. They communicate data between connected black boxes that have been predefined. FBP is said to be component-oriented because these black-box processes can be connected repeatedly to form several applications without needing to be modified internally. Let's explore FBP in more detail.
Flow-based programming (FBP)
I think FBP is a good blend of workflow and dataflow. FBP uses a data factory metaphor to define an application. It sees an application as a network of asynchronous processes that start at some point and do a single sequential process that does one operation at a time until it ends, rather than communicating by using a stream of structured chunks of data. This is called an information packet (IP). This view focuses on the data and its transformation process to produce the output that is needed. Networks are usually defined outside a process as a list of connections that is interpreted by a piece of software called a scheduler.
Processes communicate via fixed capacity connections. Connections are connected to processes using ports. The port has a specific name that is agreed on by the network definition and the process code. At this point, it is possible to execute the same code by using multiple processes. A particular IP is usually only owned by a single process or transferred between two processes. The port can be either a normal type or an array type.
FBP applications typically run faster than traditional programs, since FBP processes can continue to run as long as there is room to put in data and output to process. It does not require any special programming and makes optimal use of all the processors on the machine.
FBP has a high-level, functional style so that the behavior of the system can be easily defined; for example, in a distributed multi-party protocol such as a distributed data flow model, for accurately analyzing the criteria for determining whether a variable or statement behaves correctly:
Figure 1.2 – Simple FBP design example
Now that you have a solid understanding of FBP, let's learn how Node-RED can be implemented in this way.
What is Node-RED?
Node-RED is one of the FBP tools that we have described so far. Developed by IBM's Emerging Technology Services team, Node-RED is now under the OpenJS Foundation.
Overview
FBP was invented by J. Paul Morrison in the 1970s. As we mentioned earlier, FBP describes the behavior of the application as a black box network, which in Node-RED is described as a "node." Processing is defined in each node; data is given to it, processing is performed using that data, and that data is passed to the next node. The network plays the role of allowing data to flow between the nodes.
This kind of programming method is very easy to use to make a model visually and makes it easy to access for several layer users. Anybody can understand what the flow is doing if a problem is broken down into each step. That's why you don't need to the code inside the nodes:
Figure 1.3 – Node-RED Flow Editor as an FBP tool
Flow editor and runtime
Node-RED is not only a programming tool but also an execution platform that wraps up the Node.js runtime for applications that are built using Node-RED.
We need to use the flow editor to make Node-RED applications for IoT, web services, and more. The flow editor is also a Node.js web application. We will ...