docs-v2/content/influxdb3/cloud-serverless/reference/client-libraries/v2/javascript/nodejs/install.md

4.5 KiB

title description menu influxdb3/cloud-serverless/tags weight aliases prepend
Install the InfluxDB v2 JavaScript client library Install the Node.js JavaScript client library to write data to InfluxDB Cloud Serverless.
influxdb3_cloud_serverless
name parent
Install Node.js
client libraries
JavaScript
100
/influxdb3/cloud-serverless/reference/api/client-libraries/nodejs/install
block content
warn ### Use InfluxDB v3 clients The `/api/v2/query` API endpoint and associated tooling, such as InfluxDB v2 client libraries and the `influx` CLI, **can't** query an {{% product-name omit=" Clustered" %}} cluster. [InfluxDB v3 client libraries](/influxdb3/cloud-serverless/reference/client-libraries/v3/) and [Flight SQL clients](/influxdb3/cloud-serverless/reference/client-libraries/) are available that integrate with your code to write and query data stored in {{% product-name %}}. InfluxDB v3 supports many different tools for [**writing**](/influxdb3/cloud-serverless/write-data/) and [**querying**](/influxdb3/cloud-serverless/query-data/) data. [**Compare tools you can use**](/influxdb3/cloud-serverless/get-started/#tools-to-use) to interact with {{% product-name %}}.

Install the Node.js JavaScript client library to write data to InfluxDB {{% product-name %}}.

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 {{% product-name %}}, see InfluxDB URLs.

  3. In your terminal, create a directory for your Node.js project and change to it.

    mkdir influx-node-app && cd influx-node-app
    
  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
    

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
    
  2. Enter the following command to create a TypeScript configuration (tsconfig.json) with default values:

    tsc --init
    
  3. Run the TypeScript compiler. To recompile your code automatically as you make changes, pass the --watch, -w flag to the compiler.

    tsc --watch
    

Install dependencies

Use the @influxdata/influxdb-client JavaScript client library to write data in {{% product-name %}}.

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

npm i --save @influxdata/influxdb-client

The @influxdata/influxdb-client-apis client library package won't work with {{% product-name %}}. It only works with InfluxDB v2 management APIs.

Configure credentials

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

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

export INFLUX_URL=https://{{< influxdb/host >}}
export INFLUX_TOKEN=API_TOKEN
export INFLUX_ORG=ORG_ID
export INFLUX_BUCKET=BUCKET_NAME

Replace the following:

  • API_TOKEN: InfluxDB API token with write permission to the bucket.
  • ORG_ID: InfluxDB organization ID
  • BUCKET_NAME: the name of the {{% product-name %}} bucket to write to

Next steps

Once you've installed the client library and configured credentials, you're ready to write data.

{{< page-nav next="/influxdb3/cloud-serverless/reference/client-libraries/v2/javascript/nodejs/write/" keepTab=true >}}