---
title: InfluxDB v2 JavaScript client library for web browsers
description: Use the InfluxDB v2 JavaScript client library in browsers and front-end clients to write data to an InfluxDB Clustered database.
url: https://docs.influxdata.com/influxdb3/clustered/reference/client-libraries/v2/javascript/browser/
estimated_tokens: 2441
product: InfluxDB Clustered
version: clustered
---

# InfluxDB v2 JavaScript client library for web browsers

### Use InfluxDB 3 clients

The `/api/v2/query` API endpoint and associated tooling, such as InfluxDB v2 client libraries and the `influx` CLI, **can’t** query an InfluxDB cluster.

[InfluxDB 3 client libraries](/influxdb3/clustered/client-libraries/v3/) are available that integrate with your code to write and query data stored in InfluxDB Clustered.

InfluxDB 3 supports many different tools for [**writing**](/influxdb3/clustered/write-data/) and [**querying**](/influxdb3/clustered/query-data/) data. [**Compare tools you can use**](/influxdb3/clustered/get-started/#tools-to-use) to interact with InfluxDB Clustered.

Use the [InfluxDB v2 JavaScript client library](https://github.com/influxdata/influxdb-client-js) in browsers and front-end clients to write data to an InfluxDB Clustered 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](/influxdb/v2/get-started/).

### 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**](/influxdb/v2/reference/cli/influx/auth/create/#create-a-read-only-authentication-token) whenever possible to prevent unauthorized writes and deletes.
    

-   [Before you begin](#before-you-begin)
-   [Use with module bundlers](#use-with-module-bundlers)
-   [Use bundled distributions with browsers and module loaders](#use-bundled-distributions-with-browsers-and-module-loaders)
-   [Get started with the example app](#get-started-with-the-example-app)

## Before you begin

1. Install [Node.js](https://nodejs.org/en/download/package-manager/) 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 your InfluxDB 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

1. Configure InfluxDB properties for your script.
    
    ```html
    <script>
      window.INFLUX_ENV = {
        url: 'https://cluster-host.com',
        token: 'DATABASE_TOKEN'
      }
    </script>
    ```
    
2. Import modules from the latest client library browser distribution. `@influxdata/influxdb-client-browser` exports bundled ESM and UMD syntaxes.
    
    <!-- Tabbed content: Select one of the following options -->
    
    
    **ESM:**
    
    ```html
    <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>
    ```
    
    
    
    **UMD:**
    
    ```html
    <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>
    ```
    
    
    
    <!-- End tabbed content -->
    

After you’ve imported the client library, you’re ready to [get started writing data with the example app](#get-started-with-the-example-app).

## Get started with the example app

The client library includes an example browser app that writes to your InfluxDB instance.

1. Clone the [influxdb-client-js](https://github.com/influxdata/influxdb-client-js) repo.
    
2. Navigate to the `examples` directory:
    
    ```js
    cd examples
    ```
    
3. Update `./env_browser.js` with your InfluxDB cluster URL, your database name as `bucket`, an arbitrary string as `org`, and your database token.
    
4. Run the following command to start the application at http://localhost:3001/examples/index.html
    
    ```sh
    npm run browser
    ```
    
    `index.html` loads the `env_browser.js` configuration, the client library ESM modules, and the application in your browser.
    

For more examples, see how to [write data using the JavaScript client library for Node.js](/influxdb3/clustered/reference/client-libraries/v2/javascript/nodejs/write/).

#### Related

-   [Write data with the InfluxDB v2 JavaScript client library](/influxdb3/clustered/reference/client-libraries/v2/javascript/nodejs/write/)

[client libraries](/influxdb3/clustered/tags/client-libraries/) [JavaScript](/influxdb3/clustered/tags/javascript/)
