1.0.8 • Published 6 years ago

influxdb-node v1.0.8

Weekly downloads
13
License
ISC
Repository
bitbucket
Last release
6 years ago

InfluxDB Javascript Client

This repository contains the javascript client of the InfluxDB time series database server from InfluxData. This client is officially supported by InfluxData.

The documentation here only covers the client API in Javascript. For more information about the InfluxDB server please consult the server documentation.

Quick Install

To quickly add the InfluxDB javascript client to your Node.js project:

$ npm install --save influxdb-nodejs

Overview

A full featured client written in ECMAScript 2015.

  • Supports write batching and query result post-processing
  • Supports Node.js 0.10 and later (note that all the examples are written using ES6 which is supported by Node.js natively since version 4)
  • Provides easy access to the core InfluxDB API.

Setup

You may check the reference documentation as well.

Connect to a database

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

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

    // the connect call below is optional; if you won't do it, connection
    // will be initiated on the first read/write from/to InfluxDB
    connection.connect().then(() => {
       console.log('Connection established successfully');
    }).catch((e) => {
       console.error('Unexpected Error',e);
    });

Write to a database

    const dataPoint1 = {
        measurement : 'outdoorThermometer',
        timestamp: new Date(),
        tags: {
            location: 'greenhouse'
        },
        fields: { temperature: 23.7 }
    };

    // you can also provide tag and field data as arrays of objects:
    const dataPoint2 = {
        measurement : 'outdoorThermometer',
        timestamp: new Date().getTime()+1000000,
        tags: [ 
            { 
                key: 'location', 
                value: 'outdoor' 
            }
        ],
        fields: [ 
            { 
                key: 'temperature', 
                value: 23.7 
            } 
        ]
    };

    const series = [dataPoint1, dataPoint2];
    connection.write(series).catch(console.error);
    
    // if you need to, you may enforce emptying write buffers between
    // your application and InfluxDB
    connection.flush().then(() => {
        console.log('Data written into InfluxDB')
    }).catch(console.error);

Read from a database

    connection.executeQuery('select * from outdoorThermometer group by location').then((result) => {
        console.log(result);
    }).catch(console.error);

Drop data from a database

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

    connection.executeQuery('drop measurement outdoorThermometer').then(() => {
      console.log('Measurement dropped');
    }).catch(console.error);

Releases

  • Version 1.0.0 - Initial release
1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago