Introduction
It is a free, JavaScript-based server and web GUI programming tool for wiring together hardware devices, online services, and APIs.
Primarily, designed for the Internet of Things, but Node-RED can also be used for other type of applications to very easily assemble flows of numerous services.
Originally created by the IBM Emerging Technology organization, Node-RED is included in IBM’s Bluemix, a PaaS (Platform-as-a-Service) IoT starter application package.
Additionally, Node-RED can also be deployed separately using the Node.js application.
With Node-RED, users can mend together Web services and hardware simply by replacing common low-level coding tasks by using a visual drag-drop interface. To create a flow, a range of components in Node-RED are connected together and most of the required code is created automatically.
Features of Node-RED
The major features of Node-RED are:
- It supports browser-based flow editing. The browser-based editor that makes it easier for the user to wire together flows using the range of nodes available in the palette that can be deployed in a single-click.
- Built on Node.js, it supports a lightweight runtime environment along with the event driven and non-blocking model.
- The numerous flows created in Node-RED are stored using JSON, which can be easily imported and exported for sharing with others.
- It can easily fit on most widely used devices like Raspberry Pi, BeagleBone Black, Arduino, Android based devices, etc.
- You can run it locally (Docker support, etc).
- It can run in the cloud environment like Bluemix, AWS, MS-Azure, etc.
Where can Node-RED be used?
Node-RED can be used in an array of applications. Some of the major ones include:
- In Bluemix, for connecting to IoT (with ReST and MQTT).
- For storing IoT data for present and future computation.
- For binding and connecting to databases (MongoDB).
- For social media, when taking action and when event-driven applications are needed (like Twitter).
Node-RED has hit 1 million all-time npm installs (as of Mar 2018), which is an incredible milestone. It also has a dedicated community and is built with robust and widely popular architecture using Node.js.
Node-RED can also be used in event-driven and fast-to-market services and applications, using easily implementable steps.
Creating your First Flow
Source: nodered.org
Once Node-RED is running, point a local browser at http://localhost:1880. You can always use a browser from another machine if you know the ip address or name of the Node-RED instance – http://{Node-RED-machine-ip-address}:1880
- Add an Inject node
The Inject node allows you to inject messages into a flow, either by clicking the button on the node, or setting a time interval between injects.
Drag one onto the workspace from the palette.
Open the sidebar (Ctrl-Space, or via the dropdown menu) and select the Info tab.
Select the newly added Inject node to see information about its properties and a description of what it does.
- Add a Debug node
The Debug node causes any message to be displayed in the Debug sidebar. By default, it just displays the payload of the message, but it is possible to display the entire message object.
- Wire the two together
Connect the Inject and Debug nodes together by dragging between the output port of one to the input port of the other.
- Deploy
At this point, the nodes only exist in the editor and must be deployed to the server.
Click the Deploy button. Simple as that.
With the Debug sidebar tab selected, click the Inject button. You should see numbers appear in the sidebar. By default, the Inject node uses the number of milliseconds since January 1st, 1970 as its payload. Let’s do something more useful with that.
- Add a Function node
The Function node allows you to pass each message though a JavaScript function.
Wire the Function node in between the Inject and Debug nodes. You may need to delete the existing wire (select it and hit delete on the keyboard).
Double-click on the Function node to bring up the edit dialog. Copy the follow code into the function field:
// Create a Date object from the payload
var date = new Date(msg.payload);
// Change the payload to be a formatted Date string
msg.payload = date.toString();
// Return the message so it can be sent on
return msg;
Click Ok to close the edit dialog and then click the deploy button.
Now when you click the Inject button, the messages in the sidebar will be more readable time stamps.
If you want to build an application, get in touch with our team. We will help you build the best application for you and your business.