InfluxDB v2 JavaScript client library for web browsers
Use InfluxDB 3 clients to query
InfluxDB 3 supports compatibility endpoints for writing data using InfluxDB v2 and v1 tools. However, the /api/v2/query API endpoint and associated tooling, such as InfluxDB v2 client libraries and the influx CLI, can’t query data stored in InfluxDB 3 Enterprise.
InfluxDB 3 client libraries are available that integrate with your code to write and query data stored in InfluxDB 3 Enterprise.
Compare tools you can use to interact with InfluxDB 3 Enterprise.
Use the InfluxDB v2 JavaScript client library in browsers and front-end clients to write data to an InfluxDB 3 Enterprise database.
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:
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.
Use short-lived, read-only tokens whenever possible to prevent unauthorized writes and deletes.
- Before you begin
- Use with module bundlers
- Use bundled distributions with browsers and module loaders
- Get started with the example app
Before you begin
Install Node.js to serve your front-end app.
Ensure that InfluxDB is running and you can connect to it. For information about what URL to use to connect to your InfluxDB 3 Enterprise cluster, contact your InfluxData account representative.
Use with module bundlers
If you use a module bundler like Webpack or Parcel, install @influxdata/influxdb-client-browser.
Use bundled distributions with browsers and module loaders
Configure InfluxDB properties for your script.
<script> window.INFLUX_ENV = { url: 'https://localhost:8181', token: 'DATABASE_TOKEN' } </script>Import modules from the latest client library browser distribution.
@influxdata/influxdb-client-browserexports bundled ESM and UMD syntaxes.