Can we write InfluxQL in Influxdb 2.0 and above using @influxdata/influxdb-client or influx dependencies in NodeJs? If yes How?

const influx = new Influx.InfluxDB({
host: ‘localhost’,
database: ‘database’,
port: 8086,
org
});

influx.getDatabaseNames()
.then(names => {
res.send(names)
})

I’m getting error for running the above query in influxdb 2.2 :
Error: A 401 Unauthorized error occurred: {“code”:“unauthorized”,“message”:“Unauthorized”}

Hi @Nik,
Welcome to the community :slight_smile: . Please make sure you have mapped your buckets first to a DB and then make sure you include the authorisation requirements: Query data with InfluxQL | InfluxDB OSS 2.3 Documentation

Please give legitimate answers… I have mapped the buckets to DB

i don’t want baseless statements

@ Jay_Clifford or any others

Hi @Nik,
Here is an example based on the V1 client library.


// Connect over HTTPS
const Influx = require('influx');
const os = require('node:os');

// influx cloud example
const influx = new Influx.InfluxDB({
 host: 'us-east-1-1.aws.cloud2.influxdata.com',
 port: 443,
 protocol: 'https',
 database: 'server',
 username: '<USERNAME>',
 password: '<TOKEN>',
})
// influx OSS example
const influx = new Influx.InfluxDB({
 host: 'localhost',
 port: 8086,
 protocol: 'http',
 database: 'server',
 username: '<USERNAME>',
 password: '<TOKEN>',
})

influx.query('select * from cpu').then(results => {
    console.log(results)
  })

In future please remember this forum is here to promote collaboration and goodwill between us and the community. My initial statement was to check if you have completed this step before moving further. Using statements such as “I don’t want baseless statements” in future will not get you further in your queries.

Okay…Fantastic Thank you