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();
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());
})()
Frequently Asked Questions
-
Using REST connections requires starting taosadapter.
sudo systemctl start taosadapter
-
Node.js versions
@tdengine/client
supports Node.js v10.9.0 to 10.20.0 and 12.8.0 to 12.9.1. -
"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 name | version | TDengine version | Description |
---|---|---|---|
@tdengine/rest | 3.0.0 | 3.0.0 | Supports TDengine 3.0. Not compatible with TDengine 2.x. |
td2.0-rest-connector | 1.0.7 | 2.4.x;2.5.x;2.6.x | Removed default port 6041。 |
td2.0-rest-connector | 1.0.6 | 2.4.x;2.5.x;2.6.x | Fixed affectRows bug with create, insert, update, and alter. |
td2.0-rest-connector | 1.0.5 | 2.4.x;2.5.x;2.6.x | Support cloud token |
td2.0-rest-connector | 1.0.3 | 2.4.x;2.5.x;2.6.x | Supports connection management, standard queries, system information, error information, and continuous queries |