Node-RED for App Development: Looking at the Pros and Cons
Node-RED is a tool for visual application development by connecting nodes. With this tool you can quickly create an application for the Internet of Things, data processing, web services without having to write code. Let's look at the main features of Node-RED, its pros and cons
The basic idea behind Node-RED is to create a tool for rapid application development for the Internet of Things, mobile applications, data interaction and other tasks that don't require writing code.
In Node-RED, the concept of data flows is used to describe the logic. A stream consists of sequentially connected nodes, each of which performs an elementary function: filtering, transformation, call of an external service. Nodes receive data, process it and pass it on, thus forming a processing pipeline. A message in the pipeline is a JSON object with the fields msg.payload for basic data, msg.topic, msg.timestamp and other metadata.
Node-RED comes with a set of base nodes:
- Inject - generates messages, used to start the thread
- Debug - outputs data to the console for debugging
- Function - executes JavaScript code
- Change - converts messages
- Switch - distributes messages to different branches based on rules
- Template - generates messages based on a template
- Delay - delays messages
- Trigger - generates scheduled messages
- Link in/out - inputs and outputs for communication with other systems
- HTTP in/out - interaction with web services
- MQTT in/out - working with MQTT brokers
- TCP in/out - message exchange over TCP sockets
- WebSocket in/out - interaction via WebSocket protocol
- CSV - work with files in CSV format
- JSON - conversion to/from JSON
- XML - XML processing
This is not a complete list, and there are many additional nodes to integrate with different services and perform common tasks. By combining nodes, you can create very flexible applications for a wide range of tasks.
Tasks for which Node-RED is already in use
Internet of Things (IoT). Node-RED is often used to collect data from sensors, devices, controllers. Nodes for MQTT, TCP, Serial protocols allow easy integration of these devices. There are also nodes for popular platforms like Arduino, Raspberry Pi. Node-RED is often used to collect data from temperature, humidity, light sensors, as well as control household devices via MQTT.
Web applications. With the help of HTTP nodes you can quickly create a backend for a web application – process requests, work with databases, call external APIs. And for the frontend part export streams to static web pages.
Chatbots. Node-RED is perfect for creating chatbots – there are ready-made nodes for messaging platforms like Telegram, Slack, Facebook Messenger. The logic of message processing can be implemented visually.
ETL. Using nodes for working with databases, CSV files, cloud storage, you can flexibly implement ETL processes - data extraction, transformation and loading.
API Gateways. Node-RED allows you to quickly create an API gateway to integrate heterogeneous services - for example, to proxy requests from a mobile application to internal enterprise systems. For example, Node-RED can be used to implement an API gateway for a store's mobile application that proxies requests to internal store systems and provides a single access point for client applications.
In general, Node-RED can be used to solve a very wide range of tasks, combining existing nodes and developing your own if necessary - it will be especially handy for frontend and backend developers who have experience with JavaScript and Node.js.
Main advantages of Node-RED as a development platform
Support for different levels of context:
- Node – local data within a node,
- Flow – data to be exchanged between nodes
- Global text available to all threads and nodes in the application.
The application level context can also be used to store global settings, cache, database access objects and other common data. This feature makes development in Node-RED convenient and scalable by separating logic and data.
Large library of nodes. Node-RED has ready-made solutions for almost any task. The libraries are installed as npm-packages and contain additional nodes that can be used in the same way as the standard ones, thus integrating the necessary features into Flow:
- work with databases: postgres, mysql, mongodb, etc. Allow to perform CRUD operations.
- work with cloud services: AWS, Azure, Watson and many others. Provide nodes to interact with APIs of these services.
- machine learning: tensorflow, PyTorch, OpenCV. Contains nodes for integrating machine learning models.
- IoT: Arduino, Raspberry Pi, modbus. Allows you to connect sensors and devices.
- Web services: HTTP, Websocket, API, OAuth. Nodes for interacting with web applications.
- media: audio, video, text, images. Processing and analyzing multimedia content.
- utilities: email, SMS, FTP, JSON, Excel, etc.
Accordingly, by combining nodes it is possible to create very flexible applications.
Ease of deployment. Node-RED applications can be easily deployed in the cloud or containerized in Docker. In fact, Node-RED can be run on any platform that has Node.js – from Raspberry Pi to servers in the cloud. As for the latter, integration with container management platforms (Kubernetes, Docker Swarm) for orchestration of Node-RED clusters is possible.
Node-RED supports several options for deploying created applications:
- Installation on your own server running Linux/Windows.
- Run in a docker container on-premises or in the cloud.
- Deploy to platforms like AWS, Azure, Google Cloud.
- Export to static web applications (for front-end part).
You can set up a webhook from version control systems (GitHub, GitLab) to automate the deployment.
Detailed documentation. You can see descriptions and examples for all types of nodes without leaving the application. There is also Cookbook consists of best practices for creating applications on Node-RED.
There is a component for debugging code. There is a Debug node that allows you to output messages to a separate console and inspect data passing through the node. There is a possibility to handle exceptions inside nodes and output errors to the console. There is error logging with filtering by logging levels.
Easy management and configuration. There is built-in SSH support for remote access and administration. There is also a web-interface for managing flows, viewing logs, monitoring. There is extensive customization of user access rights and security policies.
Easy import and export. Node-RED allows you to export created flows to JSON format and import them back. This makes it easy to transfer logic between different environments, and to share flows between developers. For example, a flow can be designed in one environment and then exported and imported into production.
Monitoring. There is a built-in log console and traffic interface with information about node throughput. You can also enable advanced debugging logs and node execution statistics. For more complex cases, there is an API and the ability to integrate external monitoring systems.
Open Source. Node-RED, being an open source product, has a number of advantages over commercial NoCode platforms:
- Free of charge. Node-RED can be used absolutely free of charge, without paying license fees. This lowers the entry threshold for developers and companies.
- Openness of the source code. Anyone can study the code of Node-RED, make their contribution, correct errors. This contributes to the rapid development of the product.
- Extensibility. Due to the open architecture, the community has created many additional nodes for different tasks. They can be easily plugged in.
- Portability. Node-RED can be run on any platform, from Raspberry Pi to servers in the cloud. There is no lock-in to a specific stack.
- Integratability. Open APIs and protocols make it easy to integrate Node-RED with other systems and services.
- Community. A large community of developers and users ready to help with Node-RED - there is a forum. Node-RED community has created and published a large number of libraries and floo examples.
The main disadvantages of Node-RED
Performance. Node-RED is not designed for high-load applications. In particular, the platform uses a single-threaded data processing model and does not have a distributed data processing system. Therefore, in large-scale projects it is necessary to use external services for resource-intensive operations or transfer part of the logic to external microservices.
Binding to JS and Node.js. The main language of Node-RED is JavaScript. This is due to the technological peculiarities of the platforms). Support for other languages is limited, but can be realized through communication protocols with other services built into Node-RED. You can also use npm-modules with wrappers to C++, Java, Rust libraries. Finally, for some languages there are extensions for support inside Node-RED.
Challenges of Collaboration. Node-RED was not originally designed as a tool for collaboration and joint development of large applications in teams.
However, the community is working to improve the collaborative's capabilities:
- There is now Git support for storing Node-RED projects, which allows you to organize collaboration through repositories.
- User authorization and differentiation of access rights to nodes is implemented.
- Advanced import/export capabilities of individual streams are presented.
- Utilities for comparing different versions of threads and merging them have appeared.
- Best practices of organizing large projects with division into subsystems are being developed.
Conclusion
Node-RED is a convenient tool for rapid prototyping and integration applications. For these tasks, it is especially well suited for front- and backend developers who have experience with JavaScript. In general, Node-RED deserves attention as an innovative platform for flexible integration of heterogeneous systems, prototyping large projects, creating small auxiliary integrations and automation.
Useful resources for learning how to use Node-RED
- Official documentation - https://nodered.org/docs
- Nodes and threads library from the community - https://flows.nodered.org/
- Community Forum - https://discourse.nodered.org/
- Sample applications - https://flows.nodered.org/gallery
- Project Repository - https://github.com/node-red
- Design Practices - https://cookbook.nodered.org/