Home Reference Source Repository

Typedef

Static Public Summary
public

A ConnectionConfiguration must be provided when calling Connection.create so that you can start writing data into InfluxDB.

public

DataPoint can be passed into Connection.write(dataPoint) method so that you can write points to the database.

public

Field is a key-value pair in InfluxDB’s data structure that records metadata and the actual data value.

public

FieldType is an enumeration of InfluxDB field data types.

public

This is the main import of the influxdb-node.js package.

public

Schema describes tags and fields that can be used with a measurement.

public

Tag is a key-value pair in InfluxDB’s data structure that records metadata.

Static Public

public ConnectionConfiguration: Object source

A ConnectionConfiguration must be provided when calling Connection.create so that you can start writing data into InfluxDB.

Properties:

NameTypeAttributeDescription
username String
  • optional
  • default: 'root'

Username for connecting to the database.

password String
  • optional
  • default: 'root'

Password for connecting to the database.

database String
  • optional

Database to work with

autoCreateDatabase Boolean
  • optional
  • default: true

Automatically create database if it doesn't exist yet. To successfully connect to InfluxDB with autoCreateDatabase=true the database user authentication must be turned off or you must have admin privileges granted

hostUrl String
  • optional
  • default: 'http://127.0.0.1:8086'

InfluxDB host url to connect to. For InfluxCloud use https scheme and don't forget to pass username and password properties. For UDP access use a URL in the following form: udp://127.0.0.1:8089. For more information on using the UDP InfluxDB service check the documentation https://github.com/influxdata/influxdb/blob/master/services/udp/README.md

schema Schema[]
  • optional

schema of measurements accessed by this connection, validated when writing data points into InfluxDB. See Schema for more information.

autoGenerateTimestamps Boolean
  • optional
  • default: true

When writing data points without a timestamp:

  • If set to true the timestamp will be filled in automatically when Connection.write method is called
  • If false the timestamp will be filled in by the InfluxDB server
batchSize Number
  • optional
  • default: 1000

Number of data points in a batch. Data points written into the InfluxDBConnection are buffered in the connection until the batch size is reached or maximumWriteDelay is reached (see below.) To learn more about batching see Connection.write.

maximumWriteDelay Number
  • optional
  • default: 1000

Maximum number of milliseconds the data point can be buffered in the InfluxDBConnection. When this limit is reached for a single data point written, any older data points are also written into InfluxDB. To learn more about batching see Connection.write.

autoResolveBufferedWritePromises Boolean
  • optional
  • default: true

if true the Promise returned by Connection.write will be automatically resolved when the data are put into the buffer. This is useful for larger batch sizes for performance reasons and to avoid pollution of log files (there will be just one error generated for the whole batch on the last accepted Connection.write invocation). If false the Promise returned by Connection.write will always get rejected or resolved when the data points are written into InfluxDB. See more at Connection.write.

batchWriteErrorHandler function
  • optional

handler called when batch write to InfluxDB fails and the autoResolveBufferedWritePromises configuration property is set to true. This is useful in the case when the batch write gets triggered due to maximumWriteDelay expiration. See the example below:

To learn more about batching see Connection.write.

Example:

const InfluxDB = require('influx-nodejs')

// Connect to a single host with a full set of config details and
// a custom schema
const connection = new InfluxDB.Connection({
  database: 'my_db',
  username: 'influxUser33',
  password: 'awesomeflux!',
  hostUrl: 'http://db1.example.com:8086' },
  schema: [{
    measurement: 'serverLoad',
    tags: ['hostname'],
    fields: {
      memory_usage: InfluxDB.FieldType.INTEGER,
      cpu_usage: InfluxDB.FieldType.FLOAT,
      is_online: InfluxDB.FieldType.BOOLEAN,
    }
  }],
  batchWriteErrorHandler(e, dataPoints) { // this is the same as the default value
    console.log('[DefaultBatchWriteErrorHandler] Error writing data points into InfluxDB:' +
      dataPoints,e);
  }
})

public DataPoint: Object source

DataPoint can be passed into Connection.write(dataPoint) method so that you can write points to the database. See: https://docs.influxdata.com/influxdb/latest/introduction/getting_started/#writing-and-exploring-data

Properties:

NameTypeAttributeDescription
measurement String

Name of the measurement

timestamp Date | String | Number
  • default: undefined
  • nullable: true

timestamp of the measurement point. You can pass the following type of values:

  • Date - a JavaScript date object (it is millisecond-precision)
  • Number - millisecond-precision Unix time
  • String - nanosecond-precision Unix time as a string.
       See https://github.com/sazze/node-nanotime if you need to generate these in Node.js
    
tags Tag[] | Object

Tags to be stored together with the data point. Two formats are supported:

  • either an array of objects with key/value properties (see the example below) or an object where its property keys serve as tag keys and object property values as tag values
fields Field[] | Object

Fields to be stored together with the data point. Two formats are supported:

  • either an array of objects with key/value properties (see the example below) or an object where its property keys serve as field keys and object property values as field values

Example:

let dataPoint1={
  measurement : 'outdoorThermometer',
  timestamp: '1465839830100400200',
  tags: { location: 'outdoor' },
  fields: { temperature: 18.3 }
}

let dataPoint2={
  measurement : 'outdoorThermometer',
  timestamp: '1465839831270501600',
  tags: [ { key: 'location', value: 'greenhouse' } ]
  fields: [ { key: 'temperature', value: 23.7 } ]
}

public Field: Object source

Field is a key-value pair in InfluxDB’s data structure that records metadata and the actual data value. See: https://docs.influxdata.com/influxdb/latest/concepts/glossary/#field

Properties:

NameTypeAttributeDescription
key String

The key part of the key-value pair that makes up a field.

value String | Number | Boolean

The value part of the key-value pair that makes up a field.

Example:

let field={
  key: 'temperature',
  value: 23.7
}

public FieldType: Number source

FieldType is an enumeration of InfluxDB field data types.

Example:

const schema = {
  measurement: 'my_measurement',
  fields: {
    my_int: FieldType.INTEGER,
    my_float: FieldType.FLOAT,
    my_string: FieldType.STRING,
    my_boolean: FieldType.BOOLEAN
  }
}

public InfluxDB: Object source

This is the main import of the influxdb-node.js package.

Properties:

NameTypeAttributeDescription
Connection Connection

reference to the Connection object

FieldType FieldType

reference to the FieldType object, used to define measurement schemas

Example:

const InfluxDB=require('influxdb-nodejs');

const connection=new InfluxDB.Connection({
      hostUrl: 'http://localhost:8086',
      database: 'mydb'
});

...

public Schema: Object source

Schema describes tags and fields that can be used with a measurement.

It's recommended, but not required to use a schema; it is used to:

  • Coerce your data (properly converting JavaScript Number to either floats or integers that are available in InfluxDB)
  • Provide immediate error feedback if data supplied to the {@Connection#write} method are not compliant with the schema. An error is signaled when there is a field/tag which is not present in your schema, or the data type of a field does not match the schema.

See FieldType for available field types.

Properties:

NameTypeAttributeDescription
measurement String

Name of the measurement

fields Object[]
  • optional

Field names and their corresponding types for the given measurement. If left undefined no field validation will be executed.

tags String[]
  • optional

List of allowed tag names for the measurement. If left undefined no tag validation will be executed.

Example:

const schema = {
  measurement: 'my_measurement',
  tags: ['someTag', 'someOtherTag']
  fields: {
    my_int: InfluxDB.FieldType.INTEGER,
    my_float: InfluxDB.FieldType.FLOAT,
    my_string: InfluxDB.FieldType.STRING,
    my_boolean: InfluxDB.FieldType.BOOLEAN
  }
}

public Tag: Object source

Tag is a key-value pair in InfluxDB’s data structure that records metadata. See: https://docs.influxdata.com/influxdb/latest/concepts/glossary/#tag

Properties:

NameTypeAttributeDescription
key String

The key part of the key-value pair that makes up a tag.

value String

The value part of the key-value pair that makes up a tag

Example:

let tag={
   key: 'location',
   value: 'outdoor'
}