forked from mschae16/node-influx-highcharts-sample
/
mini.js
44 lines (40 loc) · 1.46 KB
/
mini.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { InfluxDB, Point, HttpError } = require('@influxdata/influxdb-client')
const { url, token, org, bucket } = require('./env')
const { OrgsAPI, BucketsAPI } = require('@influxdata/influxdb-client-apis')
const influxDB = new InfluxDB({ url, token })
console.log(`Using organization "${url}"`)
// =
// const Influx = require('influx');
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const hanalei = require('./data/tides-hanalei.js');
const hilo = require('./data/tides-hilo.js');
const honolulu = require('./data/tides-honolulu.js');
const kahului = require('./data/tides-kahului.js');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static(path.join(__dirname, 'public')));
app.set('port', 3000);
const queryApi = new InfluxDB({ url, token }).getQueryApi(org)
const fluxQuery =
'from(bucket:"ocean_tides") |> range(start:0) |> filter(fn: (r) => r.location == "Hanalei Bay, Kauai Island, Hawaii")'
queryApi.queryRows(fluxQuery, {
next(row, tableMeta) {
const o = tableMeta.toObject(row)
console.log(
`${o}`
// `${o._time} ${o._measurement} in '${o.location}': ${o._field}=${o._value}`
)
},
error(error) {
console.error(error)
console.log('\nFinished ERROR queryRows')
},
complete(results) {
console.log('\nFinished SUCCESS queryRows', results)
},
})