Documentation

Install the InfluxDB v2 JavaScript client library

Use InfluxDB 3 clients to query

InfluxDB 3 supports compatibility endpoints for writing data using InfluxDB v2 and v1 tools. However, the /api/v2/query API endpoint and associated tooling, such as InfluxDB v2 client libraries and the influx CLI, can’t query data stored in InfluxDB 3 Core.

InfluxDB 3 client libraries are available that integrate with your code to write and query data stored in InfluxDB 3 Core.

Compare tools you can use to interact with InfluxDB 3 Core.

Install Node.js

  1. Install Node.js.

  2. Ensure that InfluxDB is running and you can connect to it. For information about what URL to use to connect to your InfluxDB 3 Core cluster, contact your InfluxData account representative.

  3. In your terminal, create a directory for your Node.js project and change to it.

    mkdir influx-node-app && cd influx-node-app
    
    • Copy
    • Fill window
  4. Enter the following command to generate an npm package for your project.

    • npm: the package manager included with Node.js
    • -y: uses defaults for the package and bypasses prompts
    npm init -y
    
    • Copy
    • Fill window

Install TypeScript

Many of the client library examples use TypeScript. Follow these steps to initialize the TypeScript project:

  1. Install TypeScript and type definitions for Node.js.

    npm i -g typescript && npm i --save-dev @types/node
    
    • Copy
    • Fill window
  2. Enter the following command to create a TypeScript configuration (tsconfig.json) with default values:

    tsc --init
    
    • Copy
    • Fill window
  3. Run the TypeScript compiler. To recompile your code automatically as you make changes, pass the --watch, -w flag to the compiler.

    tsc --watch
    
    • Copy
    • Fill window

Install dependencies

Use the @influxdata/influxdb-client JavaScript client library to write data in InfluxDB 3 Core.

Open a new terminal window and install the @influxdata/influxdb-client package for querying and writing data:

npm i --save @influxdata/influxdb-client
  • Copy
  • Fill window

The @influxdata/influxdb-client-apis client library package won’t work with InfluxDB 3 Core. It only works with InfluxDB v2 management APIs.

Configure credentials

The client examples include an env module for accessing your InfluxDB properties from environment variables or from env.js. The examples use these properties to interact with the InfluxDB API.

Set environment variables or update env.js with your InfluxDB database, organization (required, but ignored), database token, and cluster URL.

export INFLUX_URL=https://localhost:8181
export INFLUX_TOKEN=DATABASE_TOKEN
export INFLUX_ORG=ORG_ID
export INFLUX_DATABASE=DATABASE_NAME
  • Copy
  • Fill window

Replace the following:

  • DATABASE_TOKEN: InfluxDB database token
  • ORG_ID: An arbitrary string (InfluxDB ignores this credential, but the client library requires it)
  • DATABASE_NAME: InfluxDB database name

Next steps

Once you’ve installed the client library and configured credentials, you’re ready to write data to InfluxDB.


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

Now Generally Available

InfluxDB 3 Core and Enterprise

Start fast. Scale faster.

Get the Updates

InfluxDB 3 Core is an open source, high-speed, recent-data engine that collects and processes data in real-time and persists it to local disk or object storage. InfluxDB 3 Enterprise builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries and optimized storage. A free tier of InfluxDB 3 Enterprise is available for non-commercial at-home or hobbyist use.

For more information, check out: