Get started with Node-RED

Yacine Rezgui
IBM watsonx Assistant
5 min readJun 3, 2016

--

Node-RED is a project created by two IBMers, Nick O’Leary, and Dave Conway-Jones, as a visual tool for wiring together hardware devices, APIs, and online services without writing code.

The project became popular recently as it’s the fastest way to prototype web services during a hackathon or an experiment within a company. It’s quite appreciated by developers who connect it to IoT devices.

Connected foosball at the IBM Watson Summit in Japan — May 2016

So now it’s time to get our hands on the tool. First, let’s deploy Node-RED as a NodeJS app. You can run it locally by cloning the project from GitHub or just click on this image and follow instructions to deploy it on Bluemix.

As soon as you log in, you will have to confirm the deployment and open Node-RED when the process is done.

Once deployment was done, you’ll be redirected to the Bluemix dashboard. Wait your app is running before opening Node-RED. Its route will be displayed under the app name. Now we have our Node-RED, hooray!

Congratulations :)

Don’t forget to read the section related to security on how to set credentials to avoid anonymous visitors using your app.

Once your flow editor is open:

  • drag an inject node from the sidebar to the canvas
  • double click to configure it
  • select the type and change it from timestamp to string
  • write anything as part of the payload

Second step, drag a function node (you can search it in the sidebar) into the main canvas and edit it. You can see we have now a code editor. You can write any NodeJS compatible code in this node.

Before changing the code within this modal, let me explain you a bit the architecture of this project. When you drag nodes and connect them, Node-RED links the output of the previous node as the input of the next one. Imagine it as a pipe. Within this code, the msg represents your flow and its property payload represents the current content given by the previous node as input to the current one.

In my example, msg.payload value is A girl has no name.

By the way, Game of Thrones season 6 is so good !

Now let’s change this text to upper case. Replace the current code by this one:

msg.payload = msg.payload.toUpperCase();
return msg;

Save settings and drag a debug node which will show us the value of the payload. Finally connect the nodes between each other in the specific order as shown in this screenshot:

Now we have to deploy our flows to save them. Click on the top right button, confirm the deployment (ignore the warning) and wait for the process to be done. It’s just a matter of seconds. You’ll have a green notification when it’s ready to use.

It’s time to try! Just click on the button next to your inject node (the one on the left) and watch the debug tab on the right sidebar.

You can see the result on the right sidebar thanks to the debug node

We can’t stop just here. Let’s export the flow we just created! Select the nodes we dragged into the canvas and select export to clipboard on the right menu:

Copy the content of the modal to a file and re-add the flow it by pasting the code into the text input of import modal. Don’t forget to deploy the new flow to save it.

Sweet :)

As you can see, Node-RED is really simple to use. No need to deploy a project through Terminal, everything is visual. In can be good for testing an idea, create an API or write your business process management.

If you want to read more about Node-RED, have a look to these links:

Feel free to contribute at any of these projects, they’re open source :)

In my next article, I will show you how can we create a web service in Node-RED using IBM Watson APIs. Stay tuned!

--

--

Yacine Rezgui
IBM watsonx Assistant

🇫🇷🇹🇳 Developer Relations Engineer 🥑 on Android working on privacy @Google in London. Hacking projects on free time