Unable to query data via Node.js

I have a Node.js application that I am trying to get to query InfluxDB’s cloud offering, I have set it up so I can write data fine now I need the query part. My data contains a few values - or will anyways - I have an elapsed time, service, and serviceID.

Here is my query when I output it before running it

fluxValue: 'from(bucket: "perf_mon")\n' +
    '|> range(start: duration(v: "-7d"))\n' +
    '|> filter(fn: (r) => r["_measurement"] == "elapsedtime")\n' +
    '|> filter(fn: (r) => r["_field"] == "elapsedtime")\n' +
    '|> filter(fn: (r) => r["serviceADD"] == "service")\n' +
    '|> filter(fn: (r) => r["abcdxyz"] == "serviceID")

Here it is from the query builder

from(bucket: "perf_mon")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "elapsedTime")
  |> filter(fn: (r) => r["_field"] == "elapsedTime")
  |> filter(fn: (r) => r["serviceADD"] == "service")
  |> filter(fn: (r) => r["abcdxyz"] == "serviceID")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Here is my full code - just in a single file to test out the pattern.

const queryApi = new InfluxDB({url, token}).getQueryApi(org)
const start = fluxDuration('-7d')
const measurement = 'elapsedtime'
const service = 'serviceADD'
const serviceID = 'abcdxyz'
const fluxQuery = flux`from(bucket: "${bucket}")
|> range(start: ${start})
|> filter(fn: (r) => r["_measurement"] == "${measurement}")
|> filter(fn: (r) => r["_field"] == "${measurement}")
|> filter(fn: (r) => r["${service}"] == "service")
|> filter(fn: (r) => r["serviceID"] == "serviceID")`

console.log('query:', fluxQuery)
console.log('*** QUERY ROWS ***')

queryApi.queryRows(fluxQuery, {
  next(row, tableMeta) {
    const o = tableMeta.toObject(row)
      `${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
  error(error) {
    console.log('\nFinished ERROR')
  complete() {
    console.log('\nFinished SUCCESS')

I got 95% of that code from the examples in the github repo for the package

My question/support requests comes in that I would like to know how to make it so I can query InfluxDB and get back my data in a format which I can then either process or send directly to my front end. What am I missing in the code and/or query that makes it so I can’t get data back either via my script or via the InfluxDB cloud console?

You have to rely upon javascript Promise to collect query results. https://influxdata.github.io/influxdb-client-js/influxdb-client.queryapi.collectrows.html returns a Promise that you can await in an asynchronous function. Alternatively, you can chain the promise with then(data => {/* do what you want to do with data */}).

Please see comments in the query example at https://github.com/influxdata/influxdb-client-js/blob/master/examples/query.ts#L35