Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Mangani <[email protected]>
  • Loading branch information
lmangani authored Jun 29, 2023
1 parent 5e86791 commit b5cf417
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions examples/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,49 @@ Example gRPC Flight SQL API client using NodeJS
Install and import the [Influxdb3-js library](https://github.com/bonitoo-io/influxdb3-js)

```
import {InfluxDB} from '@influxdata/influxdb3-client/src'
const {InfluxDBClient, Point} = require('@influxdata/influxdb3-client');
let url = 'https://eu-central-1-1.aws.cloud2.influxdata.com/';
let database = 'my-database';
let token = 'my-token';
const token = "abc123"
const org = "company"
const bucket = "sensors"
const database = org + "_" + bucket
let client = new InfluxDB({url: url, database: database, token: token});
async function main() {
await insert()
await query()
}
main()
async function insert(){
// Connect to HTTP API for inserting line protocol
const host = "http://localhost:8080"
const client = new InfluxDBClient({host, token})
const line = `stat,unit=temperature avg=20.5,max=45.0`
await client.write(line, bucket, org)
client.close()
}
async function query(){
// Connect to gRPc API for querying using flightsql
const host = "http://localhost:8082"
const client = new InfluxDBClient({host, token })
// Execute query
const query = `
SELECT * FROM "stat"
WHERE
time >= now() - interval '5 minute'
AND
"unit" IN ('temperature')
`
const queryResult = await client.query(query, database, queryType)
for await (const row of queryResult) {
console.log(`avg is ${row.avg}`)
console.log(`max is ${row.max}`)
}
client.close()
}
```

### TBD

0 comments on commit b5cf417

Please sign in to comment.