You are on page 1of 33

LAB-I

Introduction to Node-RED
Introduction to Node-RED
• Node-RED is a programming tool for wiring together hardware devices, APIs and
online services in new and interesting ways.
• Node-RED is a flow-based programming tool, originally developed by
IBM’s Emerging Technology Services team and now a part of the JS Foundation
• It provides a browser-based editor that makes it easy to wire together flows using the
wide range of nodes in the palette that can be deployed to its runtime in a single-click.
• Low-code programming for event-driven applications.
• Easily access from browser based
• Open source
• Being used in major cloud services
– AT&T, AT&T IoT Platform
– Cisco, Meraki
– Nokia, Innovation Platform
– Fujitsu, COLMINA Platform
– Siemens, MindSphere
– Hitachi Vantara, Lumada
– IBM, IBM Cloud
Flow-based programming
• It is a way of describing an application’s behavior as
a network of black-boxes, or “nodes”.
• Each node has a well-defined purpose; it is given
some data, it does something with that data and
then it passes that data on.
• The network is responsible for the flow of data
between the nodes.
• It is a model that lends itself very well to a visual
representation and makes it more accessible to a
wider range of users.
Browser-based flow editing
RUNNING Node-RED
run at the edge of the network on low-cost hardware such as the Raspberry Pi
as well as in the cloud.
Runtime/Editor
• Within the browser you create your application by
dragging nodes from your palette into a workspace
and start to wire them together. With a single click,
the application is deployed back to the runtime where
it is run.
• Node-RED consists of a Node.js based runtime that
you point a web browser at to access the flow editor.
• The palette of nodes can be easily extended by
installing new nodes created by the community and
the flows you create can be easily shared as JSON files.
Built on Node.js
• The light-weight runtime is built on Node.js,
taking full advantage of its event-driven, non-
blocking model.
• This makes it ideal to run at the edge of the
network on low-cost hardware such as the
Raspberry Pi as well as in the cloud.
• With over 225,000 modules in Node's package
repository, it is easy to extend the range of
palette nodes to add new capabilities.
Social Development
Getting Started
with Node-RED
• https://nodered.org/docs/getting-started/
To install Node-RED locally you will need
a supported version of Node.js

Node-RED currently recommends Node


12.x LTS.

To install Node-RED you can use the npm


command that comes with node.js
MAC Installation steps
Node.js installation
• https://nodejs.org/en/download/
Check the version of node.js & npm
Node-Red Installation
Ignore Warnings & errors
Run Node-RED
Run the browser
• http://127.0.0.1:1880
Editor Window components
Editor window components
• The header at the top, containing the deploy
button, main menu, and, if user
authentication is enabled, the user menu.
• The palette on the left, containing the nodes
available to use.
• The main workspace in the middle, where
flows are created.
• The sidebar on the right
https://nodered.org/docs/user-g
uide/editor/
Know more about browser window
User Guide

https://nodered.org/docs/user-guide
/
Hello,World! Example
• Step 1- Add an inject node
• Step 2- Add a Debug node
• Step 3- Deploy and Run
Adding an inject node
• To inject a message into the flow
– From the node palette on the left side of the Node-RED editor, select an Inject node and
drag it onto the flow
– Double-click the node to open the “Edit inject node” view
– For the Payload field, select string and enter Hello, world! in the text field
– Click Done.
Adding a Debug node
• print out our message to the debug console window.
– From the node palette, select a Debug node and drag it onto the flow, and then
place it to the right-hand side of the Inject node.
– Wire the nodes together. Place the mouse cursor over the Inject node’s output
port (a small gray square on the right-hand side of the node), then left-click and
drag a wire over to the input port of the Debug node. A gray wire should now be
connecting the output of the Inject node to the input of the Debug node.
Deploy and Run
• to deploy it to the server and run it
– Click the Deploy button.
– Click the Debug tab in the right-hand side of the editor window.
– Click the Inject node’s button, which is the blue square coming out from the left-hand side of the
Inject node. Clicking the button is what will inject a message into the flow.
– A “Hello, world!” message should appear in the debug window.
– Click the Inject node again to send another message.
Example –II (Using Function)
• Step 1 - Add a Function node
• Step 2 - Add Code and Run
• Step 3 - Add Two-Second Interval
Adding a Function node
• the Function block, which allows you to enter JavaScript code to manipulate the
msg object.
– Select a Function node and drag it out onto the flow.
– Carefully place it over the existing wire between the existing Inject and Debug nodes. Node-
RED will insert the new node between the two existing nodes, and rewire the nodes
together.
Add Code and Run
• Double-click on the Function node to open the “Edit function node”
view.
• Copy and paste the following JavaScript code into the Function field:
– var dateNow = new Date(); var timeAsString =
dateNow.toLocaleTimeString(); msg.payload = msg.payload
+ ' The time is ' + timeAsString + '.'; return msg
• In the Name field, enter “Add time to msg”.
• Click Done.
• Click Deploy.
• Click the Inject node’s button.
• In the Debug tab, you should see the new output. For example,
“Hello, world! The time is 4:25:29 PM”
List of Exercises to Solve
• Write a program for String Count : counting
number of words and number of characters in the
following format:
– The entered string : Hello World
– Number of characters in the string : 10
– Number of Words in the string:2
• Write a Program to convert the temperature given
as Degrees to Fahernheit using the formula in
Node-RED
• (T°C × 9/5) + 32 = X°F

You might also like