Node-RED nodes for writing data to InfluxDB v3.
This package provides Node-RED integration with InfluxDB v3 using the official @influxdata/influxdb3-client JavaScript library.
cd ~/.node-red
npm install node-red-contrib-influxdb3cd ~/.node-red
npm install /path/to/node-red-contrib-influxdb3- Clone this repository
- Install dependencies:
npm install
- Link to your Node-RED installation:
cd ~/.node-red npm install /path/to/node-red-contrib-influxdb3
- Restart Node-RED
This package includes two nodes:
A configuration node that stores connection details for your InfluxDB v3 instance.
Configuration:
- Name: A friendly name for the connection
- Host: Your InfluxDB v3 host URL (e.g.,
https://us-east-1-1.aws.cloud2.influxdata.com) - Token: Your InfluxDB v3 authentication token
- Database: The default database (bucket) name
Writes data points to InfluxDB v3.
Configuration:
- Connection: Select an InfluxDB v3 config node
- Name: Optional node name
- Measurement: Default measurement name (can be overridden by
msg.measurement) - Database: Optional database override (uses connection default if not set)
The write node accepts data in multiple formats:
Send data as a string in InfluxDB line protocol format:
msg.payload = "temperature,location=room1 value=21.5";
return msg;Send an object with explicit fields and tags properties:
msg.measurement = "temperature";
msg.payload = {
fields: {
value: 21.5,
humidity: 65
},
tags: {
location: "room1",
sensor: "dht22"
},
timestamp: Date.now() // optional
};
return msg;Send an object where all properties (except 'tags' and 'timestamp') are treated as fields:
msg.measurement = "environment";
msg.payload = {
temperature: 21.5,
humidity: 65,
pressure: 1013.25,
tags: {
room: "bedroom",
floor: "2"
}
};
return msg;Important: By default, all numbers are written as floats to avoid schema conflicts in InfluxDB. This is because JavaScript doesn't distinguish between 1.0 and 1 (both equal 1), which can cause issues when InfluxDB expects a float but receives an integer.
When using object format, the node handles data types as follows:
- Numbers: Written as float fields by default
- Integers: Must be explicitly marked (see below)
- Booleans: Written as boolean fields
- Strings: Written as string fields
- Tags: Always converted to strings
To write integers explicitly, use one of these methods:
Method 1: Using the integers array
msg.payload = {
fields: {
temperature: 21.5, // float
count: 42, // will be float by default
total: 100 // will be float by default
},
integers: ['count', 'total'] // mark these as integers
};Method 2: Using the i suffix
msg.payload = {
fields: {
temperature: 21.5, // float
count: "42i", // integer (note the string with 'i' suffix)
total: "100i" // integer
}
};Example with both floats and integers:
msg.measurement = "sensor_data";
msg.payload = {
temperature: 21.5, // float
humidity: 65.0, // float (even though it looks like an integer)
event_count: "50i", // integer
tags: {
location: "room1"
}
};The following message properties can be used to override node configuration:
msg.measurement- Override the measurement namemsg.database- Override the database namemsg.timestamp- Set the timestamp for the data point (Date object or milliseconds)msg.payload.integers- Array of field names to write as integers (e.g.,['count', 'total'])
// Function node
msg.measurement = "temperature";
msg.payload = {
value: 21.5,
tags: {
location: "living_room",
sensor_id: "temp_001"
}
};
return msg;// Function node
msg.measurement = "environment";
msg.payload = {
fields: {
temperature: 22.3,
humidity: 58,
co2: 412,
light: 850
},
tags: {
room: "office",
floor: "3",
building: "A"
}
};
return msg;[MQTT In] --> [JSON Parse] --> [Function] --> [InfluxDB v3 Write]
Function node:
// Parse MQTT topic for location
const location = msg.topic.split('/')[1];
msg.measurement = "sensor_data";
msg.payload = {
temperature: msg.payload.temp,
humidity: msg.payload.hum,
tags: {
location: location
}
};
return msg;// Function node - direct line protocol
const location = "warehouse";
const temp = 18.5;
const humidity = 72;
msg.payload = `climate,location=${location} temperature=${temp},humidity=${humidity}`;
return msg;// Write to different databases based on data type
if (msg.payload.type === "critical") {
msg.database = "critical-events";
} else {
msg.database = "general-logs";
}
msg.measurement = "events";
msg.payload = {
severity: msg.payload.severity,
message: msg.payload.msg,
tags: {
type: msg.payload.type
}
};
return msg;Import this flow into Node-RED to get started:
[
{
"id": "influxdb3-config-node",
"type": "influxdb3-config",
"name": "My InfluxDB v3",
"host": "https://us-east-1-1.aws.cloud2.influxdata.com",
"database": "my-database"
},
{
"id": "inject-node",
"type": "inject",
"name": "Generate Data",
"props": [{"p": "payload"}],
"repeat": "5",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 100,
"wires": [["function-node"]]
},
{
"id": "function-node",
"type": "function",
"name": "Format Data",
"func": "msg.measurement = 'temperature';\nmsg.payload = {\n value: 20 + Math.random() * 10,\n tags: {\n location: 'office'\n }\n};\nreturn msg;",
"x": 320,
"y": 100,
"wires": [["influxdb3-write-node"]]
},
{
"id": "influxdb3-write-node",
"type": "influxdb3-write",
"name": "Write to InfluxDB",
"influxdb": "influxdb3-config-node",
"measurement": "",
"database": "",
"x": 530,
"y": 100,
"wires": [["debug-node"]]
},
{
"id": "debug-node",
"type": "debug",
"name": "Debug",
"x": 730,
"y": 100,
"wires": []
}
]You can use environment variables in the configuration node:
INFLUX_HOST- InfluxDB v3 host URLINFLUX_TOKEN- Authentication tokenINFLUX_DATABASE- Default database name
Simply reference them in the Node-RED UI using ${INFLUX_HOST} syntax (if using Node-RED environment variable substitution).
- Verify your host URL is correct and includes
https:// - Check that your token has write permissions for the database
- Ensure the database name exists in your InfluxDB v3 instance
- Check the node status - it should show "written" briefly after successful writes
- Verify at least one field is provided (InfluxDB requires at least one field)
- Check that field values are not null or undefined
The node will display error status and log details to the Node-RED debug panel:
- "no config" - The InfluxDB v3 config node is not selected
- "error" - Check the debug panel for details
- Node-RED v2.0.0 or higher
- InfluxDB v3 instance (Cloud or Edge)
MIT
Contributions are welcome! Please feel free to submit a Pull Request.