If you’re interested in Node-RED, register for our webinar on Wednesday, July 2 to learn more!
When it comes to wiring together hardware devices, APIs, and online services, few tools match the simplicity and flexibility of Node-RED. As a flow-based development tool, it’s particularly popular in the IIoT space, where edge devices and sensors constantly generate time-series data.
In this post, we’ll walk through how to integrate Node-RED with TDengine and build a simple application for real-time alerts.
Prerequisites
- Ensure that TDengine and taosAdapter are running.
- Install Node-RED version 3.0.0 or later. For more information, see the official documentation.
- Install the TDengine Node.js client library.
- Install the TDengine Node-RED plugin.
Integrate TDengine with Node-RED
Once you have installed the Node-RED plugin, TDengine Operator and TDengine Consumer nodes will be available to you in the Storage tab in Node-RED.
- TDengine Operator nodes write data to and query data from TDengine.
- TDengine Consumer nodes subscribe to topics in TDengine.
When you deploy these nodes in Node-RED, you must specify the hostname and port number of your TDengine instance as well as the username and password used to log in to TDengine. For Consumer nodes, you must also subscribe to at least one topic. You can use these nodes to integrate TDengine into your Node-RED applications.

Example
A workshop has multiple smart meters, each generating one data record every second. Data is stored in TDengine, with real-time calculations performed every minute showing power consumption and average current and voltage per meter. Alerts are triggered when current exceeds 25 A or voltage exceeds 230 V.
1. Set Up TDengine
-
In TDengine, create a database for the test data:
CREATE DATABASE smartmeters;
-
Create a supertable for the test data:
CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupid INT, location VARCHAR(24));
-
Create three tables, one for each smart meter:
CREATE TABLE smartmeters.d0 USING smartmeters.meters TAGS (1, 'workshop1'); CREATE TABLE smartmeters.d1 USING smartmeters.meters TAGS (2, 'workshop1'); CREATE TABLE smartmeters.d2 USING smartmeters.meters TAGS (3, 'workshop1');
-
Create a topic for alerting on overload:
CREATE TOPIC topic_overload AS SELECT tbname,* FROM smartmeters.meters WHERE current > 25 OR voltage > 230;
2. Add Writer Nodes
-
Select the tdengine-operator node in the node palette and drag it to the canvas.
-
Double-click the node to open property settings, fill in the name as ‘td-writer’, and click the “+” icon to the right of the database field.
-
In the pop-up window, enter the following:
- Name: ‘db-server’.
- Connection type: “Connection string”.
- Input:
ws://root:taosdata@www.example.com:6041
-
Click “Add” and return.
3. Simulate Device Data
-
Select the ‘function’ node from the palette and drag it before ‘td-writer’ on the canvas.
-
Double-click the node:
- Name: ‘write d0’.
- Select “Function” tab and enter:
// Generate random values const current = Math.floor(Math.random() * (30 - 5 + 1)) + 5; // 5-30A const voltage = Math.floor(Math.random() * (240 - 198 + 1)) + 198; // 198-240V const phase = Math.floor(Math.random() * (3 - 1 + 1)) + 1; // 1-3 // Create SQL msg.topic = `insert into test.d0 values (now, ${current}, ${voltage}, ${phase});`; return msg;
-
Drag an “inject” node before ‘write d0’.
-
Configure the inject node:
- Name: “inject1”.
- Trigger: “Repeat”.
- Interval: 1 second.
-
Repeat steps 1-4 for other devices (d1, d2).
4. Add Output Monitor
- Drag a ‘debug’ node after ‘td-writer’.
- Configure it as follows:
- Name: ‘debug1’.
- Node status: checked.
- Select ‘Message count’ from the drop-down list.
After adding all nodes, connect them in sequence to form a pipeline. Click “Deploy” to publish changes. When running successfully:
- ‘td-writer’ turns green.
- ‘debug1’ shows data count.

5. Query Data
-
Drag an inject node to the canvas:
- Name: ‘query’.
- Set msg.topic to:
SELECT tbname, AVG(current), AVG(voltage), SUM(p) FROM (SELECT tbname, current, voltage, current*voltage/60 AS p FROM smartmeters.meters WHERE ts > now-60s PARTITION BY tbname) GROUP BY tbname;
-
Drag tdengine-operator node to canvas:
- Database: Select existing ‘db-server’ connection.
- Save and return.
-
Drag debug node to canvas and configure it:
- Name: ‘debug2’.
- Node status: checked.
- Select ‘Message count’ from the drop-down list.
-
Connect nodes sequentially and click “Deploy”.
When the flow is successfully started:
- ‘td-reader’ node turns green.
- Debug node shows result count.

6. Subscribe to Overload Data
- Drag tdengine-consumer node to canvas:
- Name: td-consumer.
- Subscription Server:
ws://www.example.com:6041
. - Username: root.
- Password: taosdata.
- Topics: topic_overload.
- Initial Offset: latest.
- Other settings: default.
- Drag debug node to canvas and configure it:
- Name: ‘debug3’.
- Node status: checked.
- Select ‘Message count’ from the drop-down list.
- Connect nodes sequentially and click “Deploy”.
When operational:
- ‘td-consumer’ node turns green.
- Debug node shows consumption count.
Complete workflow overview:

You now receive alerts from the td-consumer node when current or voltage exceed the configured limits. An example is shown as follows:
{
"topic": "topic_overload",
"payload": [
{
"tbname": "d1",
"ts": "1750140456777",
"current": 31,
"voltage": 217,
"phase": 2,
"groupid": 4,
"location": "California.MountainView"
}
],
"database": "test",
"vgroup_id": 4,
"precision": 0
}