Documentation

Install the InfluxDB v2 JavaScript client library

Use InfluxDB v3 clients

The /api/v2/query API endpoint and associated tooling, such as InfluxDB v2 client libraries and the influx CLI, can’t query an InfluxDB cluster.

InfluxDB v3 client libraries and Flight SQL clients are available that integrate with your code to write and query data stored in InfluxDB Clustered.

InfluxDB v3 supports many different tools for writing and querying data. Compare tools you can use to interact with InfluxDB Clustered.

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 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
    
  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
    

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
    
  2. Enter the following command to create a TypeScript configuration (tsconfig.json) with default values:

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

    tsc --watch
    

Install dependencies

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

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

npm i --save @influxdata/influxdb-client

The @influxdata/influxdb-client-apis client library package won’t work with InfluxDB Clustered. 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://cluster-host.com
export INFLUX_TOKEN=DATABASE_TOKEN
export INFLUX_ORG=ORG_ID
export INFLUX_DATABASE=DATABASE_NAME

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

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered