2696 api browserjs fixes (#3005)

* fix: broken link (#2696).

* fix: correct errors in javascript for browsers. Added token warning. (#2696)

* WIP - split Javascript guide into separate pages.

* WIP - Revised and split JavaScript browser

* WIP fix: errors in browser and node js client library.

* fix: simplify and correct JavaScript for browsers. Remove separate library entry. Assume users will prefer ESM. Simplify instructions for the browser example app.

* fix: add import instruction

* fix: Redo Javascript browser doc. Break down the use cases and improve examples.

* fix: browser use cases for JS module distributions.

* fix: browser package should be used whether bundling or not.
pull/3027/head
Jason Stirnaman 2021-08-16 16:26:29 -05:00 committed by GitHub
parent c9eed1c42e
commit e8666ddc22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 142 additions and 353 deletions

View File

@ -1,180 +1,23 @@
--- ---
title: JavaScript client library title: Get started with the JavaScript client library for web browsers
seotitle: InfluxDB JavaScript client library seotitle: Get started with the InfluxDB JavaScript client library for web browsers
list_title: JavaScript (browser) list_title: JavaScript for browsers
description: > description: >
Use the JavaScript client library for web browsers to interact with InfluxDB. Use the JavaScript client library example app to interact with the InfluxDB API in web browsers.
menu: menu:
influxdb_cloud: influxdb_cloud:
name: Javascript (Browser) name: JavaScript for browsers
parent: Client libraries identifier: client_js_browsers
influxdb/v2.0/tags: [client libraries, JavaScript] parent: Client libraries
influxdb/cloud/tags: [client libraries, JavaScript]
weight: 201 weight: 201
aliases: aliases:
- /influxdb/v2.0/reference/api/client-libraries/js/ - /influxdb/cloud/reference/api/client-libraries/browserjs/
- /influxdb/cloud/api-guide/client-libraries/browserjs/write
- /influxdb/cloud/api-guide/client-libraries/browserjs/query
related:
- /influxdb/cloud/api-guide/client-libraries/nodejs/write/
- /influxdb/cloud/api-guide/client-libraries/nodejs/query/
--- ---
Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to integrate InfluxDB into JavaScript scripts and applications. This client supports both client-side (browser) and server-side (NodeJS) environments. {{% duplicate-oss %}}
This guide presumes some familiarity with JavaScript, browser environments, and InfluxDB.
If just getting started, see [Get started with InfluxDB](/influxdb/v2.0/get-started/).
## Before you begin
1. Install [NodeJS](https://nodejs.org/en/download/package-manager/).
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](/influxdb/v2.0/reference/urls/).
## Easiest way to get started
1. Clone the [examples directory](https://github.com/influxdata/influxdb-client-js/tree/master/examples) in the [influxdb-client-js](https://github.com/influxdata/influxdb-client-js) repo.
2. Navigate to the `examples` directory:
```js
cd examples
```
3. Install `yarn` or `npm` dependencies as needed:
```js
yarn install
npm install
```
3. Update your `./env` and `index.html` with the name of your InfluxDB [bucket](/influxdb/v2.0/organizations/buckets/), [organization](/influxdb/v2.0/organizations/), [token](/influxdb/v2.0/security/tokens/), and `proxy` which relies upon proxy to forward requests to the target InfluxDB.
4. Run the following command to run the application at [http://localhost:3001/examples/index.html]()
```sh
npm run browser
```
## Boilerplate for the InfluxDB Javascript client library
Use the Javascript library to write data to and query data from InfluxDB in a browser.
1. To write a data point to InfluxDB using the JavaScript library, import the latest InfluxDB Javascript library in your script.
```js
import {InfluxDB, Point} from 'https://unpkg.com/@influxdata/influxdb-client/dist/index.browser.mjs'
```
2. Define constants for your InfluxDB [bucket](/influxdb/v2.0/organizations/buckets/), [organization](/influxdb/v2.0/organizations/), [token](/influxdb/v2.0/security/tokens/), and `proxy` which relies on a proxy to forward requests to the target InfluxDB instance.
```js
const proxy = '/influx'
const token = 'example-token'
const org = 'example-org'
const bucket = 'example-bucket'
```
3. Instantiate the InfluxDB JavaScript client and pass in the `proxy` and `token` parameters.
```js
const influxDB = new InfluxDB({proxy, token})
```
## Write data to InfluxDB with JavaScript
Use the Javascript library to write data to InfluxDB in a Node.js environment.
1. Instantiate an `InfluxDB` client. Provide your InfluxDB `url` and `token`.
2. Use the `getWriteApi` method of the instantiated InfluxDB client to create a **write client**. Provide your InfluxDB `org` and `bucket`.
```js
import {InfluxDB, Point} from '@influxdata/influxdb-client'
const influxDB = new InfluxDB({url, token})
const writeApi = influxDB.getWriteApi(org, bucket)
```
The `useDefaultTags` method instructs the write api to use default tags when writing points. Create a [point](/influxdb/v2.0/reference/glossary/#point) and write it to InfluxDB using the `writePoint` method. The `tag` and `floatField` methods add key value pairs for the tags and fields, respectively. Close the client to flush all pending writes and finish.
```js
writeApi.useDefaultTags({location: 'browser'})
const point1 = new Point('temperature')
.tag('example', 'index.html')
.floatField('value', 24)
console.log(`${point1}`)
writeApi.writePoint(point1)
writeApi.close()
```
### Complete example write script
```js
const influxDB = new InfluxDB({proxy, token})
const writeApi = influxDB.getWriteApi(org, bucket)
// setup default tags for all writes through this API
writeApi.useDefaultTags({location: 'browser'})
const point1 = new Point('temperature')
.tag('example', 'index.html')
.floatField('value', 24)
console.log(` ${point1}`)
writeApi.writePoint(point1)
// flush pending writes and close writeApi
writeApi
.close()
.then(() => {
console.log('WRITE FINISHED')
})
```
## Query data from InfluxDB with JavaScript
Use the Javascript library to query data from InfluxDB.
1. Use the `getQueryApi` method of the `InfluxDB` client to create a new **query client**. Provide your InfluxDB `org`.
```js
const queryApi = influxDB.getQueryApi(org)
```
2. Create a Flux query (including your `bucket` parameter).
```js
const fluxQuery =
'from(bucket:"<my-bucket>")
|> range(start: 0)
|> filter(fn: (r) => r._measurement == "temperature")'
```
The **query client** sends the Flux query to InfluxDB and returns line table metadata and rows.
3. Use the `next` method to iterate over the rows.
```js
queryApi.queryRows(fluxQuery, {
next(row: string[], tableMeta: FluxTableMetaData) {
const o = tableMeta.toObject(row)
// console.log(JSON.stringify(o, null, 2))
console.log(
`${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
)
}
}
```
### Complete example query script
```js
// performs query and receive line table metadata and rows
// https://v2.docs.influxdata.com/v2.0/reference/syntax/annotated-csv/
queryApi.queryRows(fluxQuery, {
next(row: string[], tableMeta: FluxTableMetaData) {
const o = tableMeta.toObject(row)
// console.log(JSON.stringify(o, null, 2))
console.log(
'${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
)
},
error(error: Error) {
console.error(error)
console.log('\nFinished ERROR')
},
complete() {
console.log('\nFinished SUCCESS')
},
})
```
For more information, see the [JavaScript client README on GitHub](https://github.com/influxdata/influxdb-client-js).

View File

@ -6,7 +6,7 @@ menu:
influxdb_cloud: influxdb_cloud:
name: Install name: Install
parent: Node.js parent: Node.js
influxdb/v2.0/tags: [client libraries, JavaScript] influxdb/cloud/tags: [client libraries, JavaScript]
weight: 100 weight: 100
aliases: aliases:
- /influxdb/cloud/reference/api/client-libraries/js/install - /influxdb/cloud/reference/api/client-libraries/js/install

View File

@ -6,7 +6,7 @@ menu:
influxdb_cloud: influxdb_cloud:
name: Query name: Query
parent: Node.js parent: Node.js
influxdb/v2.0/tags: [client libraries, JavaScript] influxdb/cloud/tags: [client libraries, Node.js, JavaScript]
weight: 201 weight: 201
aliases: aliases:
- /influxdb/cloud/reference/api/client-libraries/js/query - /influxdb/cloud/reference/api/client-libraries/js/query

View File

@ -6,7 +6,7 @@ menu:
influxdb_cloud: influxdb_cloud:
name: Write name: Write
parent: Node.js parent: Node.js
influxdb/v2.0/tags: [client libraries, JavaScript] influxdb/cloud/tags: [client libraries, Node.js, JavaScript]
weight: 101 weight: 101
aliases: aliases:
- /influxdb/cloud/reference/api/client-libraries/js/write - /influxdb/cloud/reference/api/client-libraries/js/write

View File

@ -1,180 +1,118 @@
--- ---
title: JavaScript client library title: Get started with the JavaScript client library for web browsers
seotitle: InfluxDB JavaScript client library seotitle: Get started with the InfluxDB JavaScript client library for web browsers
list_title: JavaScript (browser) list_title: JavaScript for browsers
description: > description: >
Use the JavaScript client library for web browsers to interact with InfluxDB. Use the JavaScript client library example app to interact with the InfluxDB API in web browsers.
menu: menu:
influxdb_2_0: influxdb_2_0:
name: Javascript (Browser) name: JavaScript for browsers
identifier: client_js_browsers
parent: Client libraries parent: Client libraries
influxdb/v2.0/tags: [client libraries, JavaScript] influxdb/v2.0/tags: [client libraries, JavaScript]
weight: 201 weight: 201
aliases: aliases:
- /influxdb/v2.0/reference/api/client-libraries/browserjs/ - /influxdb/v2.0/reference/api/client-libraries/browserjs/
- /influxdb/v2.0/api-guide/client-libraries/browserjs/write
- /influxdb/v2.0/api-guide/client-libraries/browserjs/query
related:
- /influxdb/v2.0/api-guide/client-libraries/nodejs/write/
- /influxdb/v2.0/api-guide/client-libraries/nodejs/query/
--- ---
Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to integrate InfluxDB into JavaScript scripts and applications. This client supports both client-side (browser) and server-side (NodeJS) environments. Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to interact with the InfluxDB 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. This guide presumes some familiarity with JavaScript, browser environments, and InfluxDB.
If just getting started, see [Get started with InfluxDB](/influxdb/v2.0/get-started/). If you're just getting started with InfluxDB, see [Get started with InfluxDB](/{{% latest "influxdb" %}}/get-started/).
{{% warn %}}
### Tokens in production applications
{{% api/browser-token-warning %}}
{{% /warn %}}
* [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 ## Before you begin
1. Install [NodeJS](https://nodejs.org/en/download/package-manager/). 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. 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](/influxdb/v2.0/reference/urls/). For information about what URL to use to connect to InfluxDB OSS or InfluxDB Cloud, see [InfluxDB URLs](/{{% latest "influxdb" %}}/reference/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](/{{% latest "influxdb" %}}/api-guide/client-libraries/nodejs/).
## Use bundled distributions with browsers and module loaders
1. Configure InfluxDB properties for your script.
```html
<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.
{{< code-tabs-wrapper >}}
{{% code-tabs %}}
[ESM](#import-esm)
[UMD](#import-umd)
{{% /code-tabs %}}
{{% code-tab-content %}}
```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>
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```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>
```
{{% /code-tab-content %}}
{{< /code-tabs-wrapper >}}
After you've imported the client library, you're ready to [write data](/{{% latest "influxdb" %}}/api-guide/client-libraries/nodejs/write/?t=nodejs) 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](https://github.com/influxdata/influxdb-client-js) repo.
## Easiest way to get started
1. Clone the [examples directory](https://github.com/influxdata/influxdb-client-js/tree/master/examples) in the [influxdb-client-js](https://github.com/influxdata/influxdb-client-js) repo.
2. Navigate to the `examples` directory: 2. Navigate to the `examples` directory:
```js
```js
cd examples cd examples
``` ```
3. Install `yarn` or `npm` dependencies as needed:
```js 3. Update `./env_browser.js` with your InfluxDB [url](/{{% latest "influxdb" %}}/reference/urls/), [bucket](/{{% latest "influxdb" %}}/organizations/buckets/), [organization](/{{% latest "influxdb" %}}/organizations/), and [token](/{{% latest "influxdb" %}}/security/tokens/)
yarn install
npm install
```
3. Update your `./env` and `index.html` with the name of your InfluxDB [bucket](/influxdb/v2.0/organizations/buckets/), [organization](/influxdb/v2.0/organizations/), [token](/influxdb/v2.0/security/tokens/), and `proxy` which relies upon proxy to forward requests to the target InfluxDB. 4. Run the following command to start the application at [http://localhost:3001/examples/index.html]()
4. Run the following command to run the application at [http://localhost:3001/examples/index.html]()
```sh ```sh
npm run browser npm run browser
``` ```
## Boilerplate for the InfluxDB Javascript client library `index.html` loads the `env_browser.js` configuration, the client library ESM modules, and the application in your browser.
Use the Javascript library to write data to and query data from InfluxDB in a browser.
1. To write a data point to InfluxDB using the JavaScript library, import the latest InfluxDB Javascript library in your script.
```js
import {InfluxDB, Point} from 'https://unpkg.com/@influxdata/influxdb-client/dist/index.browser.mjs'
```
2. Define constants for your InfluxDB [bucket](/influxdb/v2.0/organizations/buckets/), [organization](/influxdb/v2.0/organizations/), [token](/influxdb/v2.0/security/tokens/), and `proxy` which relies on a proxy to forward requests to the target InfluxDB instance.
```js
const proxy = '/influx'
const token = 'example-token'
const org = 'example-org'
const bucket = 'example-bucket'
```
3. Instantiate the InfluxDB JavaScript client and pass in the `proxy` and `token` parameters.
```js
const influxDB = new InfluxDB({proxy, token})
```
## Write data to InfluxDB with JavaScript
Use the Javascript library to write data to InfluxDB in a Node.js environment.
1. Instantiate an `InfluxDB` client. Provide your InfluxDB `url` and `token`.
2. Use the `getWriteApi` method of the instantiated InfluxDB client to create a **write client**. Provide your InfluxDB `org` and `bucket`.
```js
import {InfluxDB, Point} from '@influxdata/influxdb-client'
const influxDB = new InfluxDB({url, token})
const writeApi = influxDB.getWriteApi(org, bucket)
```
The `useDefaultTags` method instructs the write api to use default tags when writing points. Create a [point](/influxdb/v2.0/reference/glossary/#point) and write it to InfluxDB using the `writePoint` method. The `tag` and `floatField` methods add key value pairs for the tags and fields, respectively. Close the client to flush all pending writes and finish.
```js
writeApi.useDefaultTags({location: 'browser'})
const point1 = new Point('temperature')
.tag('example', 'index.html')
.floatField('value', 24)
console.log(`${point1}`)
writeApi.writePoint(point1)
writeApi.close()
```
### Complete example write script
```js
const influxDB = new InfluxDB({proxy, token})
const writeApi = influxDB.getWriteApi(org, bucket)
// setup default tags for all writes through this API
writeApi.useDefaultTags({location: 'browser'})
const point1 = new Point('temperature')
.tag('example', 'index.html')
.floatField('value', 24)
console.log(` ${point1}`)
writeApi.writePoint(point1)
// flush pending writes and close writeApi
writeApi
.close()
.then(() => {
console.log('WRITE FINISHED')
})
```
## Query data from InfluxDB with JavaScript
Use the Javascript library to query data from InfluxDB.
1. Use the `getQueryApi` method of the `InfluxDB` client to create a new **query client**. Provide your InfluxDB `org`.
```js
const queryApi = influxDB.getQueryApi(org)
```
2. Create a Flux query (including your `bucket` parameter).
```js
const fluxQuery =
'from(bucket:"<my-bucket>")
|> range(start: 0)
|> filter(fn: (r) => r._measurement == "temperature")'
```
The **query client** sends the Flux query to InfluxDB and returns line table metadata and rows.
3. Use the `next` method to iterate over the rows.
```js
queryApi.queryRows(fluxQuery, {
next(row: string[], tableMeta: FluxTableMetaData) {
const o = tableMeta.toObject(row)
// console.log(JSON.stringify(o, null, 2))
console.log(
`${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
)
}
}
```
### Complete example query script
```js
// performs query and receive line table metadata and rows
// https://v2.docs.influxdata.com/v2.0/reference/syntax/annotated-csv/
queryApi.queryRows(fluxQuery, {
next(row: string[], tableMeta: FluxTableMetaData) {
const o = tableMeta.toObject(row)
// console.log(JSON.stringify(o, null, 2))
console.log(
'${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
)
},
error(error: Error) {
console.error(error)
console.log('\nFinished ERROR')
},
complete() {
console.log('\nFinished SUCCESS')
},
})
```
For more information, see the [JavaScript client README on GitHub](https://github.com/influxdata/influxdb-client-js).

View File

@ -16,11 +16,6 @@ aliases:
--- ---
Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to integrate InfluxDB into your Node.js application. Use the [InfluxDB JavaScript client library](https://github.com/influxdata/influxdb-client-js) to integrate InfluxDB into your Node.js application.
{{% note %}}
{{% api/v2dot0/nodejs/install %}}
{{% /note %}}
In this guide, you'll start a Node.js project from scratch and code some simple API operations. In this guide, you'll start a Node.js project from scratch and code some simple API operations.
{{< children >}} {{< children >}}

View File

@ -12,6 +12,7 @@ aliases:
- /influxdb/v2.0/reference/api/client-libraries/nodejs/install - /influxdb/v2.0/reference/api/client-libraries/nodejs/install
--- ---
## Install ## Install
1. Install [Node.js](https://nodejs.org/en/download/package-manager/). 1. Install [Node.js](https://nodejs.org/en/download/package-manager/).
@ -28,11 +29,8 @@ aliases:
## Install dependencies ## Install dependencies
{{% note %}} The JavaScript client contains two packages.
{{% api/v2dot0/nodejs/install %}} Add both as dependencies of your project.
{{% /note %}}
The JavaScript client contains two packages. Add both as dependencies of your project.
1. Change to your project directory: 1. Change to your project directory:
@ -52,13 +50,23 @@ The JavaScript client contains two packages. Add both as dependencies of your pr
npm install --save @influxdata/influxdb-client-apis npm install --save @influxdata/influxdb-client-apis
``` ```
## Configure your environment ## Get started with examples
Set environment variables for [bucket](/influxdb/v2.0/organizations/buckets/), [organization](/influxdb/v2.0/organizations/), [token](/influxdb/v2.0/security/tokens/), and [url](/influxdb/v2.0/urls). Your application will use these to interact with the InfluxDB API.
```sh
{{< api/v2dot0/env >}}
```
{{% note %}} {{% note %}}
The client examples include an [`env`](https://github.com/influxdata/influxdb-client-js/blob/master/examples/env.js) module for conveniently accessing environment variables. The client examples include an [`env`](https://github.com/influxdata/influxdb-client-js/blob/master/examples/env.js) module for accessing your InfluxDB properties from environment variables or from `env.js`.
The examples will use these to interact with the InfluxDB API.
{{% /note %}} {{% /note %}}
1. Set environment variables or update `env.js` with your InfluxDB [bucket](/influxdb/v2.0/organizations/buckets/), [organization](/influxdb/v2.0/organizations/), [token](/influxdb/v2.0/security/tokens/), and [url](/influxdb/v2.0/urls).
```sh
# Environment variables
{{< api/v2dot0/env >}}
```
2. Run an example script.
```sh
query.ts
```
{{% api/v2dot0/nodejs/learn-more %}}

View File

@ -14,13 +14,17 @@ aliases:
Use the Javascript library to query data from InfluxDB. Use the Javascript library to query data from InfluxDB.
1. Use the `getQueryApi` method of the `InfluxDB` client to create a new **query client**. Provide your InfluxDB `org`.
1. Instantiate an `InfluxDB` client. Provide your InfluxDB `url` and `token`.
2. Use the `getQueryApi` method of the `InfluxDB` client to create a new **query client**.
Provide your InfluxDB `org`.
```js ```js
const queryApi = influxDB.getQueryApi(org) const queryApi = influxDB.getQueryApi(org)
``` ```
2. Create a Flux query (including your `bucket` parameter). 3. Create a Flux query (including your `bucket` parameter).
```js ```js
const fluxQuery = const fluxQuery =
@ -31,7 +35,7 @@ Use the Javascript library to query data from InfluxDB.
The **query client** sends the Flux query to InfluxDB and returns line table metadata and rows. The **query client** sends the Flux query to InfluxDB and returns line table metadata and rows.
3. Use the `next` method to iterate over the rows. 4. Use the `next` method to iterate over the rows.
```js ```js
queryApi.queryRows(fluxQuery, { queryApi.queryRows(fluxQuery, {

View File

@ -12,7 +12,6 @@ aliases:
- /influxdb/v2.0/reference/api/client-libraries/nodejs/write - /influxdb/v2.0/reference/api/client-libraries/nodejs/write
--- ---
## Write data to InfluxDB with JavaScript
Use the Javascript library to write data to InfluxDB in a Node.js environment. Use the Javascript library to write data to InfluxDB in a Node.js environment.
1. Instantiate an `InfluxDB` client. Provide your InfluxDB `url` and `token`. 1. Instantiate an `InfluxDB` client. Provide your InfluxDB `url` and `token`.

View File

@ -0,0 +1,7 @@
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.0/reference/cli/influx/auth/create/#create-a-read-only-authentication-token) whenever possible to prevent unauthorized writes and deletes.

View File

@ -1,5 +0,0 @@
This library supports browser and server-side (Node.js) Javascript environments. Use the @influxdata/influxdb-client module when targeting Node.js. The module supports both CommonJS and ES Module syntax.
To use InfluxDB management APIs in your project, also add @influxdata/influxdb-client-apis as a dependency to your project.
If you target the browser or deno, use @influxdata/influxdb-client-browser. It is UMD-compatible for use with module loaders. See [Javascript (browser)](/influxdb/content/v2.0/api-guide/client-libraries/js-browser) for more information.