Skip to main content

使用 Node.js 连接器建立连接

安装连接器

npm install @tdengine/rest

配置

在您的终端里面执行下面的命令设置 TDengine Cloud 令牌为环境变量:

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

替换 <token> 和 <url> 为 TDengine Cloud 的令牌和 URL 。 获取 TDengine Cloud 的令牌和 URL,可以登录TDengine Cloud 后点击左边的”编程“菜单,然后选择”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();

查看源码

客户端连接建立连接以后,想了解更多写入数据和查询数据的内容,请参考 <https://docs.taosdata.com/cloud/programming/insert/> and <https://docs.taosdata.com/cloud/programming/query/>.

想知道更多通过 REST 接口写入数据的详情,请参考REST 接口.