Documentation

Install the InfluxDB 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 InfluxDB OSS or InfluxDB Cloud, see InfluxDB URLs.

  3. Create a directory for your new Node.js project, and then change to the directory–for example, enter the following command into your terminal:

    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

The JavaScript client library contains two packages: @influxdata/influxdb-client and @influxdata/influxdb-client-apis. Add both as dependencies of your project.

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

    npm install --save @influxdata/influxdb-client
    
    • Copy
    • Fill window
  2. Install @influxdata/influxdb-client-apis for access to the InfluxDB management APIs:

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

Next steps

Once you’ve installed the JavaScript client library, you’re ready to write data to InfluxDB or get started with other examples from the client library.

Get started with examples

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

  1. Set environment variables or update env.mjs with your InfluxDB bucket, organization, token, and URL.

    export INFLUX_URL=http://localhost:8086
    export INFLUX_TOKEN=YOUR_API_TOKEN
    export INFLUX_ORG=YOUR_ORG
    export INFLUX_BUCKET=YOUR_BUCKET
    
    • Copy
    • Fill window

    Replace the following:

    • YOUR_API_TOKEN: InfluxDB API token
    • YOUR_ORG: InfluxDB organization ID
    • YOUR_BUCKET: InfluxDB bucket name
  2. Run one of the influxdb-client-js example scripts.

    query.ts
    
    • Copy
    • Fill window

For more examples and information, see the JavaScript client on GitHub.


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 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: