{"id":15652,"library":"influx","title":"InfluxDB Client for Node.js and Browsers","description":"This package, `influx`, provides a client library for interacting with InfluxDB 1.x time-series databases from Node.js and browser environments. The current stable version is 5.12.0. Releases are frequent, with several minor versions and bug fixes released annually, indicating active maintenance for the 1.x series. Key differentiators include its full support across Node.js and browsers, a simple API for common InfluxDB operations, and its focus on performance, capable of processing millions of rows per second with zero external dependencies. It's crucial to note that this library is specifically for InfluxDB v1.x; users of InfluxDB v2.x should use the official `@influxdata/influxdb-client-js` package.","status":"active","version":"5.12.0","language":"javascript","source_language":"en","source_url":"https://github.com/node-influx/node-influx","tags":["javascript","influx","influxdb","time","series","client","db","typescript"],"install":[{"cmd":"npm install influx","lang":"bash","label":"npm"},{"cmd":"yarn add influx","lang":"bash","label":"yarn"},{"cmd":"pnpm add influx","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary class for interacting with InfluxDB. For CommonJS, use `const { InfluxDB } = require('influx');` or `const InfluxDB = require('influx').InfluxDB;`","wrong":"const InfluxDB = require('influx');","symbol":"InfluxDB","correct":"import { InfluxDB } from 'influx';"},{"note":"Used for defining the schema of measurements, specifying data types for fields.","wrong":"import FieldType from 'influx/FieldType';","symbol":"FieldType","correct":"import { FieldType } from 'influx';"},{"note":"These are TypeScript interfaces for type checking, best imported using `import type` to avoid runtime overhead or issues in some environments.","wrong":"import { IPoint } from 'influx';","symbol":"IPoint","correct":"import type { IPoint, IClusterConfig } from 'influx';"}],"quickstart":{"code":"import { InfluxDB, FieldType, IPoint } from 'influx';\n\nasync function run() {\n  const host = process.env.INFLUXDB_HOST ?? 'localhost';\n  const port = parseInt(process.env.INFLUXDB_PORT ?? '8086', 10);\n  const username = process.env.INFLUXDB_USERNAME ?? 'admin';\n  const password = process.env.INFLUXDB_PASSWORD ?? 'admin';\n  const database = process.env.INFLUXDB_DATABASE ?? 'mydb';\n\n  const influx = new InfluxDB({\n    host: host,\n    port: port,\n    database: database,\n    username: username,\n    password: password,\n    schema: [\n      {\n        measurement: 'cpu_load_short',\n        fields: {\n          value: FieldType.FLOAT,\n          host: FieldType.STRING,\n        },\n        tags: ['host']\n      }\n    ]\n  });\n\n  // Ensure the database exists\n  try {\n    const dbs = await influx.getDatabaseNames();\n    if (!dbs.includes(database)) {\n      await influx.createDatabase(database);\n      console.log(`Database '${database}' created.`);\n    } else {\n      console.log(`Database '${database}' already exists.`);\n    }\n  } catch (error) {\n    console.error('Error checking/creating database:', error);\n    process.exit(1);\n  }\n\n  // Write data\n  const points: IPoint[] = [\n    {\n      measurement: 'cpu_load_short',\n      tags: { host: 'server01' },\n      fields: { value: 0.64, region: 'us-west' }\n    }\n  ];\n  await influx.writePoints(points);\n  console.log('Data written successfully.');\n\n  // Query data\n  const results = await influx.query(`\n    SELECT * FROM cpu_load_short WHERE host = 'server01' ORDER BY time DESC LIMIT 5\n  `);\n  console.log('Query results:', results);\n\n  // Example of using AbortSignal (v5.12.0 feature)\n  const controller = new AbortController();\n  const timeoutId = setTimeout(() => controller.abort(), 1000); // Abort after 1 second\n  try {\n    const abortableResults = await influx.query('SELECT * FROM cpu_load_short', {\n      abortSignal: controller.signal\n    });\n    console.log('Abortable query results:', abortableResults);\n  } catch (err: any) {\n    if (err.name === 'AbortError') {\n      console.log('Query aborted successfully.');\n    } else {\n      console.error('Abortable query failed:', err.message);\n    }\n  } finally {\n    clearTimeout(timeoutId);\n  }\n}\n\nrun().catch(console.error);","lang":"typescript","description":"This quickstart demonstrates how to connect to an InfluxDB 1.x instance, check for and create a database, write a data point, and perform a basic query. It also includes an example of using the `AbortSignal` for query cancellation, a feature introduced in v5.12.0."},"warnings":[{"fix":"Ensure your InfluxDB 1.x instance is configured to accept Basic Auth headers for authentication. If you must send credentials via URL parameters (not recommended for production), you might need to adjust client options if available, or consider downgrading temporarily if unable to update InfluxDB configuration.","message":"Starting with version 5.11.0, the client defaults to sending InfluxDB authentication credentials via a Basic Auth header instead of including them in the URL or query string. This is a security enhancement but may break existing applications if your InfluxDB setup expects credentials differently or if you were previously relying on credentials being exposed in the URL.","severity":"breaking","affected_versions":">=5.11.0"},{"fix":"If you are using InfluxDB 2.x, migrate to the official InfluxData client library for JavaScript: `@influxdata/influxdb-client-js`.","message":"This `influx` client library is explicitly designed and maintained for InfluxDB **1.x** series. It is not compatible with InfluxDB **2.x** or later versions. Using this library with an InfluxDB 2.x instance will result in connection errors, query failures, or unexpected behavior.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to `influx` version 5.9.7 or newer to resolve timestamp conversion inaccuracies.","message":"Versions of `influx` prior to 5.9.7 had a bug where timestamp conversions could be subject to floating-point errors, potentially leading to inaccurate timestamps for written data points or discrepancies in query results, particularly with large integer timestamps.","severity":"gotcha","affected_versions":"<5.9.7"},{"fix":"Upgrade to `influx` version 5.9.1 or newer to ensure correct encoding of placeholder values in queries.","message":"Prior to version 5.9.1, there were issues with incorrect encoding when using placeholders or bind parameters in InfluxDB queries, which could lead to malformed queries or failed data insertion/retrieval.","severity":"gotcha","affected_versions":"<5.9.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Double-check your `username` and `password` client options. Ensure your InfluxDB 1.x server is configured for Basic Auth. If using `influx` < 5.11.0 and upgrading, be aware of the authentication method change.","cause":"Incorrect credentials provided, or the InfluxDB server expects authentication in a different format than the client is sending. Common after `influx` v5.11.0's change to Basic Auth.","error":"Error: 'InfluxDB: authentication failed' or 'Authorization header required'"},{"fix":"For ES Modules/TypeScript, use `import { InfluxDB } from 'influx';`. If you must use CommonJS, ensure your `require` statement correctly accesses the named export: `const { InfluxDB } = require('influx');` or `const InfluxDB = require('influx').InfluxDB;`.","cause":"This error typically occurs when trying to use CommonJS `require` syntax incorrectly with a package designed for ES Modules or when the default export is being imported instead of a named export.","error":"TypeError: InfluxDB is not a constructor"},{"fix":"Before attempting to create a database, use `influx.getDatabaseNames()` to check if the database exists. Only call `createDatabase(name)` if the database name is not present in the returned list.","cause":"The `createDatabase` method was called for a database that already exists on the InfluxDB server.","error":"InfluxDB 'Error: Cannot create database \"mydb\", already exists.'"}],"ecosystem":"npm"}