← All Posts
What is Node-Red and how can I install it?

What is Node-Red and how can I install it?

Eamon O'CallaghanEamon O'CallaghanNovember 17, 2022
Share

A simple introduction to Node-RED

Node-Red is a “low-code” programming solution. It allows you to create simple programs or “flows” that can be used to accomplish many simple programming tasks with little or no programming knowledge. It provides a browser-based UI where wires can be used to connect nodes.

The image above shows a simple flow, illustrating how Node-Red works. Notice the wires connecting nodes. A flow generally starts with a blue input node. In this flow, it’s called Verify Certificate. The input node is used to start a flow (similar to a start button). In this case, it is used to inject a JSON certificate into the flow.

The purpose of this flow is to send a JSON certificate to the S1Seven servers and verify whether or not that certificate has been notarized on the blockchain.

The input data then flows along the wires between nodes from one node to the next. In this case, the second node sends an HTTP request (similar to what happens when you open a webpage) to the S1Seven servers. This particular node has been configured to send a JSON certificate to the S1Seven servers, and then pass the data that is sent back by S1Seven to the json node.

The json node takes JSON data as input and parses it as an object (a common machine-readable data structure used in programming). Then that parsed data is finally passed to the green node, which simply prints the data that has been passed into it.

To use Node-Red, it is not necessary to know all the details of how each node works, you simply need to select the nodes that do what you need and connect them to your flow.

The best way to learn to use Node-Red is to dive right in and play with it.

Installing Node-Red

There are many ways to install Node-Red, including in Azure or AWS: https://nodered.org/docs/getting-started/. This guide will show you how to install Node-Red locally on your machine.

Mac:

Node-Red depends on a program called Node. Node is an environment that allows you to run JavaScript code on your machine. First, you need to download and install Node from the following link — be sure to download the current LTS version:

Download | Node.js

Once you’ve downloaded the file, open it and follow the installation instructions to install Node. Once Node is installed, open the Terminal app and type in node --version to check that node is correctly installed. It should output something similar to v16.14.2 if it’s successfully installed.

Now we are able to continue installing Node-Red. Still in the Terminal app, input this text: sudo npm install -g --unsafe-perm node-red.

Now hit enter to start the installation. You will know that it is installed successfully when you see something like the following text: 

+node-red@1.1.0added 332 packages from 341 contributors in 18.494sfound 0 vulnerabilities

Once it is installed, type node-red into the terminal to run Node-Red. Then open your browser of choice and navigate to localhost: 1880 which is the default access point for Node-Red.

Windows:

Node-Red depends on a program called Node. Node is an environment that allows you to run JavaScript code on your machine. First, you need to download and install Node from the following link — be sure to download the current LTS version:

Download | Node.js

Once you’ve downloaded the file, open it and follow the installation instructions to install Node. Once you get to the following step, tick the box and continue with the installation. This will allow you to later install node packages that are compiled from C/C++, which may be needed to install some custom nodes for Node-Red.

637511f3f4dc55de33986e1e_1*yTZ12yPteW3F8Co5Fs1urA.png

Tools for Native Modules option

Once Node has finished installing, if you have checked the box as directed above, the following window should open automatically:

637511f38a7acf5697a36199_1*1qgkW_m64ThG_2ajFeq52w.png

Tools for Native Modules installation

Press any key to continue, and follow the instructions until the software is installed.

To verify that Node has been correctly installed, press the Windows key + R and type cmd to open the command window.

637511f4ad85c6212fe7b5f5_1*2V2YhX3V2v561HuaAxMWlw.png

The Windows run box

Once the cmd window is open, type node --version && npm --version and check that the output looks something like v16.15.0 as you can see in the screenshot below:

637511f3ab106c13c1da2aa4_1*FBGLHaHwDskUjnOzXklOog.png

Verify that Node and npm have been installed

Installing Node-Red

While still in the cmd window, type npm install -g --unsafe-perm node-red which will install Node-Red. Once it is installed, type node-red into the console to run Node-Red.

The first time that you run it, you may be prompted to allow Node access by Windows Defender on your local network, you should grant access by clicking the Allow access button.

637511f3c5306e8084e74182_1*DWJRFteIE-qqhHKybPEK5Q.png

Allow Node access on Private networks

Now Node-Red should be up and running! Open your browser of choice and navigate to localhost:1880 which is the default access point for Node-Red. You should see something similar to the image below:

637511f31c3539c984285e86_1*_xqGo0IRtgIz6TK38HXY7A.png

Node-Red initial screen

Getting started

The editor window contains three main sections:

  • The palette on the left contains the nodes available to use.
  • The main workspace is in the middle, where flows are created.
  • The sidebar on the right shows information about flows, nodes, or the debug window.

To get started, drag a blue Inject node from the palette on the left to the workspace in the middle. Also, drag a green Debug node to the workspace.

Click on the little grey dot on the right-hand side of the Inject node (its output port) to the little grey dot on the left-hand side of the Debug node (its input port). This will connect the two nodes with a wire, allowing data to flow between them.

Then click the red Deploy button on the top right of the screen. Now your changes are active and the flow can be used. In the sidebar to the right, click on the Debug tab (the third icon, the one that looks like a bug). Then click the inject button on the blue Inject node to start your flow. It should look similar to the screenshot below:

637511f3b18357d196f720c1_1*qmJi1m4Io3yR9f38ztYt1A.png

First Node-Red flow

The numbers to the right indicate the number of milliseconds since January 1st, 1970. You can click on the numbers to change the format to a more readable date. And that is the basics of how Node-Red works!

Of course, you want to be able to do more than just inject and print timestamps. The next section will show how you can interact with objects and data in Node-Red!

Interacting with objects

Node-Red works by sending msg (message) objects from one node to the next. If you are not familiar with the concept of objects from programming, you can think of them as being a bit like an email. We generally think of an email as one entity, but an email is made up of several fields: to, from, cc, body, etc.

A msg object can be likened to that email in that it is one entity, but it can have multiple properties (fields). To illustrate, double-click on the blue Inject node. Here you can see the properties of the msg object. By default, msg.payload will be set to a timestamp.

637511f3fcb9dc1c8df80889_1*mUxLA6zjufBLbbaArU96vw.png

msg.payload

As you can see in the screenshot, there is a little + add button underneath the properties. Click on that button to add a new property. You can rename the property however you like. As an example, let’s simulate an email and set 3 properties, to, from, and body.

Click on the grey drop-down menu to the right of the = sign to choose what data type you want the property to be. There are several options including string (which represents text), number, and JSON. Select string, and type in email@example.com. Set the properties to the values seen in the screenshot below and click Done when finished.

637511f35727124c7f42fcf9_1*pCT21Xa_caVVNwijyRAdHw.png

Setting properties on the msg object

Before we do anything with that data, you need to understand how to access the data. Look at the green debug node. Double-click on it, and notice that the Output is set to msg.payload. That notation means that you want to access the payload property on the msg object.

If, for example, you wanted to access the to property that you have set on the msg object, you could change payload to to. However, we want to see all the properties on the msg object, not just one. So beside Output, click the grey msg dropdown and choose complete msg object as you can see in the following screenshot:

637511f31c35390d42285e87_1*h-hgqsg0tnKp9yuQvF2IJQ.png

Select complete msg object

Now click the red Done button and click the Deploy on the top right to save your changes. Now when you click the inject button on the blue Inject node, instead of injecting a timestamp, the msg object will be sent to the debug node and printed in the debug section on the right side of your screen.

To improve the formatting, click once on the printed object. It should look similar to the screenshot below:

637511f4581fce24a35d8ffd_1*sZEsLjid3vaYzrUCntQVbA.png

Our printed msg object to the right

As you can see, the msg object has four properties:

  • _msgid — An internal id generated by Node-Red, you can ignore this.
  • to — The email that you added
  • from — The email that you added
  • body — The text that you added.

Now that you know the basics of how flows and objects work in Node-Red, you can start playing around with some of our pre-made flows that interact with the S1Seven API or show use-cases for JSON certificates.

Links to some of our pre-made flows

To see flows related to interacting with the S1Seven API, click here.

To see flows showing how incoming certificates can be saved to Azure, click here.

To see flows that show how to extract properties from JSON certificates and plot them to a graph, click here.

To see a flow that shows you how to use S1Seven’s certificate tools to convert a JSON certificate to a PDF, click here.