Skip to content

Instantly share code, notes, and snippets.

@TomyCesaille
Created April 3, 2020 16:15
Show Gist options
  • Save TomyCesaille/ef43b38411873990db64e45dcc36c7c8 to your computer and use it in GitHub Desktop.
Save TomyCesaille/ef43b38411873990db64e45dcc36c7c8 to your computer and use it in GitHub Desktop.
store data into InfluxDB 2.0 with Node.js
const { InfluxDB, FluxTableMetaData } = require('@influxdata/influxdb-client')
let client = new InfluxDB({ url: 'http://localhost:9999', token: process.env.INFLUXDB_TOKEN });
const writeApi = client.getWriteApi(process.env.INFLUXDB_ORG, process.env.INFLUXDB_BUCKET);
//...
let offlineSince = (lastSeenDate === null) ? 0 : ((new Date().getTime() - lastSeenDate.getTime()) / 1000).toFixed(0);
if (offlineSince < 0)
offlineSince = 0;
let data = `status,contactName=${contactTarget} offlineSince=${offlineSince}u`;
writeApi.writeRecord(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment