Skip to main content

Connect with Node.js

Install Client Library

npm install @tdengine/websocket

Config

Run this command in your terminal to save TDengine cloud token as variables:

export TDENGINE_CLOUD_TOKEN="<token>"
export TDENGINE_CLOUD_URL="<url>"
IMPORTANT

Replace <token> and <url> with cloud token and URL. To obtain the value of cloud token and URL, please log in TDengine Cloud and click "Programming" on left menu, then select "Node.js".

Connect

const taos = require('@tdengine/websocket');

var url = process.env.TDENGINE_CLOUD_URL;
var token = process.env.TDENGINE_CLOUD_TOKEN;
async function createConnect() {
let conn = null;
try {
let conf = new taos.WSConfig(url);
conf.setToken(token);
conn = await taos.sqlConnect(conf);
} catch (err) {
throw err;
} finally {
if (conn) {
await conn.close();
}
}
}

view source code

For how to write data and query data, please refer to Data In and Tools.

For more details about how to write or query data via REST API, please check REST API.