提交 755af48f 编写于 作者: D dingbo

docs: node

上级 4712b67a
---
sidebar_label: Node.js
title: TDengine Node.js Connector
---
\ No newline at end of file
---
`td2.0-rest-connector` are the official Node.js language connectors for TDengine. Node.js developers can develop applications to access TDengine instance data. `td2.0-rest-connector` is a **REST connector** that connects to TDengine instances via the REST API.
The Node.js connector source code is hosted on [GitHub](https://github.com/taosdata/taos-connector-node).
## Installation steps
### Pre-installation
Install the Node.js development environment
### Install via npm
```bash
npm i td2.0-rest-connector
```
## Establishing a connection
```javascript
{{#include docs/examples/node/connect.js}}
```
## Usage examples
```javascript
{{#include docs/examples/node/reference_example.js:usage}}
```
## Important Updates
| td2.0-rest-connector version | Description |
| ------------------------- | ---------------------------------------------------------------- |
| 1.0.5 | Support connect to TDengine cloud service
## API Reference
[API Reference](https://docs.taosdata.com/api/td2.0-connector/)
\ No newline at end of file
const { options, connect } = require("td2.0-rest-connector");
options.url = process.env.TDENGINE_CLOUD_URL;
options.query = { token: process.env.TDENGINE_CLOUD_TOKEN };
// ANCHOR: usage
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());
})()
// ANCHOR_END: usage
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册