Connect with Node.js
Install Client Library
npm install @tdengine/rest
Config
Run this command in your terminal to save TDengine cloud token as variables:
- Bash
- CMD
- Powershell
export TDENGINE_CLOUD_TOKEN="<token>"
export TDENGINE_CLOUD_URL="<url>"
set TDENGINE_CLOUD_TOKEN=<token>
set TDENGINE_CLOUD_URL=<url>
$env:TDENGINE_CLOUD_TOKEN='<token>'
$env:TDENGINE_CLOUD_URL='<url>'
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 { 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();
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.