Documentation

Install the InfluxDB v2 JavaScript client library

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. Start a new Node.js project. The npm package manager is included with Node.js.

npm init -y influx-node-app

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

Open a new terminal window and install @influxdata/influxdb-client:

npm i --save @influxdata/influxdb-client

The @influxdata/influxdb-client-apis client library package doesn’t work with InfluxDB v3. 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 (bucket), organization (required, but ignored), token, and cluster URL.

export INFLUX_URL=https://cluster-id.influxdb.io
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!


Introducing InfluxDB 3.0

The new core of InfluxDB built with Rust and Apache Arrow. Available today in InfluxDB Cloud Dedicated.

Learn more

State of the InfluxDB Cloud Serverless documentation

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.