Skip to main content

TDengine Node.JS Client Library

@tdengine/rest is the official Node.js language client library for TDengine. Node.js developers can develop applications to access TDengine instance data. @tdengine/rest connects to TDengine instances via the REST API.

The source code for the Node.js client library is located on GitHub.

Version support

Please refer to version support list

Installation steps

Pre-installation

Install the Node.js development environment

Install via npm

npm install @tdengine/rest

Establishing a connection

const { options, connect } = require("@tdengine/rest");

async function test() {
options.url = process.env.TDENGINE_CLOUD_URL;
options.query = { token: process.env.TDENGINE_CLOUD_TOKEN };
let conn = connect(options);
let cursor = conn.cursor();
try {
let res = await cursor.query("show databases");
res.toString();
} catch (err) {
console.log(err);
}
}

test();

view source code

Usage examples

let conn = connect(options);
let cursor = conn.cursor();
(async()=>{
let result = await cursor.query('show databases');
// print query result as taos shell
result.toString();
// Get Result object, return Result object.
console.log(result.getResult());
// Get status, return 'succ'|'error'.
console.log(result.getStatus());
// Get head,return response head (Array<any>|undefined,when execute failed this is undefined).
console.log(result.getHead());
// Get Meta data, return Meta[]|undefined(when execute failed this is undefined).
console.log(result.getMeta());
// Get data,return Array<Array<any>>|undefined(when execute failed this is undefined).
console.log(result.getData());
// Get affect rows,return number|undefined(when execute failed this is undefined).
console.log(result.getAffectRows());
// Get command,return SQL send to server(need to `query(sql,false)`,set 'pure=false',default true).
console.log(result.getCommand());
// Get error code ,return number|undefined(when execute failed this is undefined).
console.log(result.getErrCode());
// Get error string,return string|undefined(when execute failed this is undefined).
console.log(result.getErrStr());
})()

view source code

Frequently Asked Questions

  1. Using REST connections requires starting taosadapter.

    sudo systemctl start taosadapter
  2. Node.js versions

    @tdengine/client supports Node.js v10.9.0 to 10.20.0 and 12.8.0 to 12.9.1.

  3. "Unable to establish connection", "Unable to resolve FQDN"

    Usually, the root cause is an incorrect FQDN configuration. You can refer to this section in the FAQ to troubleshoot.

Important update records

package nameversionTDengine versionDescription
@tdengine/rest3.0.03.0.0Supports TDengine 3.0. Not compatible with TDengine 2.x.
td2.0-rest-connector1.0.72.4.x;2.5.x;2.6.xRemoved default port 6041。
td2.0-rest-connector1.0.62.4.x;2.5.x;2.6.xFixed affectRows bug with create, insert, update, and alter.
td2.0-rest-connector1.0.52.4.x;2.5.x;2.6.xSupport cloud token
td2.0-rest-connector1.0.32.4.x;2.5.x;2.6.xSupports connection management, standard queries, system information, error information, and continuous queries