Documentation

JavaScript client library for web browsers

Use the InfluxDB JavaScript client library to interact with the InfluxDB v2 API in browsers and front-end clients. This library supports both front-end and server-side environments and provides the following distributions:

  • ECMAScript modules (ESM) and CommonJS modules (CJS)
  • Bundled ESM
  • Bundled UMD

This guide presumes some familiarity with JavaScript, browser environments, and InfluxDB. If you’re just getting started with InfluxDB, see Get started with InfluxDB.

Tokens in production applications

The examples below configure the authentication token in source code for demonstration purposes only. To protect your data, take the following steps:

  1. Avoid sending tokens to public clients such as web browsers and mobile apps. Regard any application secret sent to client devices as public and not confidential.

  2. Use short-lived, read-only tokens whenever possible to prevent unauthorized writes and deletes.

Before you begin

  1. Install Node.js to serve your front-end app.

  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.

Use with module bundlers

If you use a module bundler like Webpack or Parcel, install @influxdata/influxdb-client-browser. For more information and examples, see Node.js.

Use bundled distributions with browsers and module loaders

  1. Configure InfluxDB properties for your script.

    <script>
      window.INFLUX_ENV = {
        url: 'http://localhost:8086',
        token: 'YOUR_AUTH_TOKEN'
      }
    </script>
    
  2. Import modules from the latest client library browser distribution. @influxdata/influxdb-client-browser exports bundled ESM and UMD syntaxes.

    <script type="module">
      import {InfluxDB, Point} from 'https://unpkg.com/@influxdata/influxdb-client-browser/dist/index.browser.mjs'
    
      const influxDB = new InfluxDB({INFLUX_ENV.url, INFLUX_ENV.token})
    </script>
    
    <script src="https://unpkg.com/@influxdata/influxdb-client-browser"></script>
    <script>
      const Influx = window['@influxdata/influxdb-client']
    
      const InfluxDB = Influx.InfluxDB
      const influxDB = new InfluxDB({INFLUX_ENV.url, INFLUX_ENV.token})
    </script>
    

After you’ve imported the client library, you’re ready to write data to InfluxDB.

Get started with the example app

This library includes an example browser app that queries from and writes to your InfluxDB instance.

  1. Clone the influxdb-client-js repo.

  2. Navigate to the examples directory:

    cd examples
    
  3. Update ./env_browser.js with your InfluxDB url, bucket, organization, and token

  4. Run the following command to start the application at http://localhost:3001/examples/index.html

    npm run browser
    

    index.html loads the env_browser.js configuration, the client library ESM modules, and the application in your browser.


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: