Install the InfluxDB v2 JavaScript client library

Install the Node.js JavaScript client library to write data to an InfluxDB Cloud Dedicated database.

Tools to execute queries

InfluxDB v2 client libraries use the InfluxDB API /api/v2/query endpoint. This endpoint can’t query an InfluxDB Cloud Dedicated database.

InfluxDB Cloud Dedicated supports many different tools for querying data, including:

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 Cloud Dedicated 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 $_
  4. Enter the following command to generate an npm package for your project. The npm package manager is included with Node.js.

    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. Create a TypeScript configuration with default values.

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

    tsc -w -p

Install dependencies

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

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 Cloud Dedicated. 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), token, and cluster URL.

export INFLUX_URL=

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!

Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

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.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

State of the InfluxDB Cloud Serverless documentation

InfluxDB Cloud Serverless documentation is a work in progress.

The new documentation for InfluxDB Cloud Serverless is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.