Open Source Low-Code with Node-RED

What is low-code?

As I’m sure you can relate, coding is not easy. It has a steep learning curve and requires a lot of time. Software developers spend ages learning, researching, prototyping, deploying, solving errors and adapting to changes when creating software. Because of this, there has always been different approaches to try to simplify application development. One of them is low-code.

Low-code development means writing less lines of code. It uses a graphical user interface and predefined visual components to simplify the creation of applications and save time. Low-code sits between traditional development and no-code development, which reduces coding to 0 but flexibility and customisation are reduced as well.

Some of the advantages of low-code platforms can be:

  • Speed: some platforms claim that low-code can be 20 times faster than traditional development by simplifying or removing coding and deploying tasks, so the team can focus on other tasks.
  • Time to market: low-code makes prototyping easier, and allows you to create MVP’s with less effort.
  • Maintainability: since the amount of code is reduced, it gets easier to read and maintain. And without requiring complex coding, it’s easy to adapt our apps to suit new requirements.
  • Cost: reducing time means reducing costs. But it also reduces the need of skilled developers, which also means reduced hiring costs.

Node-RED

Node-RED is a powerful open-source programming tool built on Node.js by IBM and now part of the OpenJS Foundation.

It provides a browser-based editor that allows creating applications by wiring predefined black box functions (nodes). There are thousands of nodes made by the community allowing us to easily integrate with a lot of services, APIs, or IoT devices.

Node-RED is light-weight and flow-oriented, which makes it ideal for stateless and event driven applications running in the cloud. 

Trying Node-RED

To test node-red capabilities, we are going to develop a Telegram Bot that returns the weather information for a given city. 

First, we need to create a TG bot and to register in OpenWeatherMap to gain use of their API. And, of course, install Node-RED. All these steps are really quick and simple.

Once Node-RED is installed, we can access to the flow editor:

Before adding any nodes, we need to add node-red-contrib-chatbot and node-red-node-openweathermap nodes, which are not included by default. We can install them by heading to “Manage palette” in the top-right corner menu. Once installed, your palette will look like this:

Once everything is ready, we add a Telegram In and Telegram Out nodes, and by clicking on them, we configure the Telegram Token, to be connected to the bot that we created before.

Then we can add a openweathermap node and, same as before, we configure the API Key to get connected to OWM API:

Next, we need to add two functions, one to parse the data from Telegram to OpenWeatherMap, and the other one to do the other way around. This is where coding occurs. Function 1 will look like this:

var query = msg.originalMessage.text.split(“,”);

msg.location = {
    city: query[0],
    country: query[1]
}
msg.tgPayload = msg.payload;
return [msg, null];

And function 2:

msg.weather = msg.payload;
msg.payload = msg.tgPayload;

msg.payload.content = “City: “ +
    msg.location.city + “, “ + msg.location.country +
    “\nWeather: “ + msg.weather.weather +
    “\nTemperature is “ + msg.weather.tempc + “ºC”;

return msg;

Almost ready; we add a switch function with a regex expression, to ensure that the input matches the desired format “City, Country” and a Text node with a message to return when the input is wrong:

And after wiring everything together and deploying, it looks really cool:

Let’s test it by chatting to our Telegram Bot:

And with no surprise we can see that it’s raining in London. It works!

In Conclusion

Low code and no-code technologies have become a hot topic in the industry. They are not yet ready to replace traditional development, but are perfect for those who are not very skilled in development and, at the same time, can help developers to create applications faster. 

Node-RED is an example of how these technologies work. By using the graphic flow editor, and with less than 20 lines of code, we were able to create a simple application integrated with a messaging platform and an external API. 

Hopefully in the future, tools like Node-RED will make developers spend less time refactoring legacy code, meaning there’s more time for adding new features or functionalities.