Automation with Node-RED

Inspired by iOS Shortcuts and Zapier, I searched for an open source solution to easily create automations through a web interface and found two projects, Node-RED and n8n.

Node-RED

As Node-RED is more low-level and mature than n8n, I picked it to create some integrations. It is a flow-based programming tool developed in Node.js and is part of the JS foundation. From the web browser, applications/flows are created by adding nodes and linking them together to send messages. Custom JavaScript code can be added in function nodes. The flows created are saved as JSON, which allows for easy sharing. To extend Node-RED, new nodes are developed by the community and published here. I really appreciated their documentation with common use cases. The fastest way to get started is using Docker Compose:

1
2
3
4
5
6
7
8
9
10
11
version: '3'
services:
nodered:
image: nodered/node-red:1.1.2
container_name: nodered
ports:
- "1880:1880"
environment:
- TZ=Europe/Lisbon
volumes:
- ./nodered-data:/data

Node-RED can even be deployed on a Raspberry Pi. If exposing it to the internet make sure to enable authentication and adequate security mechanisms such as a firewall or a reverse proxy. I will briefly describe 2 useful flows created for testing purposes.

Example flows

The first flow is triggered daily to get the title and description of the Packt daily free e-book through their API. Using the excellent Telegram Bot API, a message is sent to a channel so I never forget to download a nice book.

The second flow exposes an API with the latest projects in Product Hunt. Node-RED already has nodes to scrape HTML using selectors and a template engine to render responses, although some data transformations are required to produce the final JSON.

The flows were easy to create and topics like logging, using environment variables, web APIs and scraping were straightforward. To test them, import the code available in this gist.

Summary

Node-RED is a great tool to create small prototypes and personal automations, however I am still not convinced that low-code visual programming tools are fit for production environments due to edge cases and maintainability concerns.