Created
April 3, 2020 16:15
-
-
Save TomyCesaille/ef43b38411873990db64e45dcc36c7c8 to your computer and use it in GitHub Desktop.
store data into InfluxDB 2.0 with Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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