npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@influxdata/influxdb3-client

v2.2.0

Published

The Client that provides a simple and convenient way to interact with InfluxDB 3.

Readme

InfluxDB 3 JavaScript Client

The JavaScript Client that provides a simple and convenient way to interact with InfluxDB 3. This package supports both writing data to InfluxDB and querying data using the FlightSQL client, which allows you to execute SQL queries against InfluxDB IOx.

We offer this Getting Started: InfluxDB 3.0 Javascript Client Library video to learn more about the library and see code examples.

Installation

To write or query InfluxDB 3, add @influxdata/influxdb3-client as a dependency to your project using your favorite package manager.

npm install --save @influxdata/influxdb3-client
yarn add @influxdata/influxdb3-client
pnpm add @influxdata/influxdb3-client

If you target Node.js, use @influxdata/influxdb3-client. It provides main (CJS), module (ESM), and browser (UMD) exports.

Usage

Set environment variables:

  • INFLUX_HOST - InfluxDB address, eg. https://us-east-1-1.aws.cloud2.influxdata.com/
  • INFLUX_TOKEN - access token
  • INFLUX_DATABASE - database (bucket) name, eg. my-database
export INFLUX_HOST="<url>"
export INFLUX_DATABASE="<database>"
export INFLUX_TOKEN="<token>"

powershell

$env:INFLUX_HOST = "<url>"
$env:INFLUX_DATABASE = "<database>"
$env:INFLUX_TOKEN = "<token>"

cmd

set INFLUX_HOST=<url>
set INFLUX_DATABASE=<database>
set INFLUX_TOKEN=<token>

Create a client

To get started with influxdb client import @influxdata/influxdb3-client package.

import {InfluxDBClient, Point} from '@influxdata/influxdb3-client'

Assign values for environment variables, and then instantiate InfluxDBClient inside of an asynchronous function. Please note that token is a mandatory parameter. Make sure to close the client when it's no longer needed for writing or querying.

const host = process.env.INFLUX_HOST
const token = process.env.INFLUX_TOKEN
const database = process.env.INFLUX_DATABASE

async function main() {
    const client = new InfluxDBClient({host, token, database})

    // code goes here

    client.close()
}

main()

You can also use a provided no argument constructor for InfluxDBClient instantiation using environment variables:


async function main() {
    const client = new InfluxDBClient()

    // code goes here

    client.close()
}

main()

You can also instantiate InfluxDBClient with a connection string:


async function main() {
    const client = new InfluxDBClient('https://us-east-1-1.aws.cloud2.influxdata.com/?token=my-token&database=my-database')

    // code goes here

    client.close()
}

main()

Write data

To write data to InfluxDB, call client.write with data in line-protocol format and the database (or bucket) name.

const line = `stat,unit=temperature avg=20.5,max=45.0`
await client.write(line, database)

// Optional: prioritize tag order for first-write column order in InfluxDB 3
const point = Point.measurement('cpu')
  .setTag('region', 'us-east')
  .setTag('host', 'web-01')
  .setFloatField('usage', 0.76)
await client.write(point, database, undefined, {
  tagOrder: ['region', 'host'],
})

Query data

To query data stored in InfluxDB, call client.query with an SQL query and the database (or bucket) name. To change to using InfluxQL add a QueryOptions object with the type 'influxql' (e.g. client.query(query, database, { type: 'influxql'})).

// Execute query
const query = `
    SELECT *
    FROM "stat"
    WHERE
    time >= now() - interval '5 minute'
    AND
    "unit" IN ('temperature')
`
const queryResult = await client.query(query, database)

for await (const row of queryResult) {
    console.log(`avg is ${row.avg}`)
    console.log(`max is ${row.max}`)
}

or use a typesafe PointValues structure with client.queryPoints

const queryPointsResult = client.queryPoints(
    query,
    database,
    queryOptions
)

for await (const row of queryPointsResult) {
    console.log(`avg is ${row.getField('avg', 'float')}`)
    console.log(`max is ${row.getField('max', 'float')}`)
    console.log(`lp: ${row.asPoint('stat').toLineProtocol()}`)
}

gRPC Compression

The JavaScript client has gRPC response compression enabled by default for all query operations.

If the server chooses to compress query responses (e.g., with gzip), the client will automatically decompress them — no extra configuration is required.

Why Response Compression Cannot Be Disabled

The grpc-accept-encoding header is hardcoded in the underlying @grpc/grpc-js library:

headers.set('grpc-accept-encoding', 'identity,deflate,gzip');

This means:

  • The client always advertises support for gzip and deflate compression
  • If the server supports compression, responses will be compressed
  • There is no per-client or per-call option to disable response decompression

Request Compression

Request compression (client-to-server) can be configured using the grpcOptions setting:

const client = new InfluxDBClient({
  host: 'https://your-influxdb-host',
  token: 'your-token',
  grpcOptions: {
    // 0 = none/identity, 1 = deflate, 2 = gzip
    'grpc.default_compression_algorithm': 2,
  },
})

Although, InfluxDB servers may not support compressed requests and will reject them with an error like Content is compressed with 'gzip' which isn't supported.

Examples

For more advanced usage, see examples.

Feedback

If you need help, please use our Community Slack or Community Page.

New features and bugs can be reported on GitHub: https://github.com/InfluxCommunity/influxdb3-js

Contribution

To contribute to this project, fork the GitHub repository and send a pull request based on the main branch.

Development

Update the Flight Client

For now, we're responsible for generating the Flight client. However, its Protobuf interfaces may undergo changes over time.

To regenerate the Flight client, use the yarn flight command to execute the provided script. The script will clone the Flight Protobuf repository and generate new TypeScript files in ./src/generated/flight.

Generate files for mock server

To generate files needed for the mock server used in some tests, run the yarn flight:test command.

License

The InfluxDB 3 JavaScript Client is released under the MIT License.