使用curl均可以寫數據到influxDB,可是用node-influx老是報錯,搞了半天也沒法解決,就索性不用它了。Node.js讀寫數據到influxDB,目前已經有一個庫node-influx, 這個庫功能很是強大,可是我我的使用這個庫的時候,遇到沒法解決的問題。node
influxDB提供HTTP的API,也就是說Node.js中的axios或[request等HTTP客戶端工具是能夠直接和influx交互的。ios
須要注意的一點是,寫到influxDB的數據格式必須是二進制流。axios
const data = Buffer.from('mymeas,mytag=1 myfield=90')
複製代碼
'Content-Type': 'application/octet-stream'
複製代碼
完整代碼展現:bash
`const axios = require(``'axios'``)`
`const data = Buffer.from(``'mylog,name=wdd error_count=2003,no_send=0'``)`
`axios({`
`url:` `'[http://localhost:8923/write?db=poc&rp=poc](http://localhost:8923/write?db=poc&rp=poc)'``,`
`method:` `'post'``,`
`headers: {`
`'Content-Type'``:` `'application/octet-stream'`
`},`
`data: data`
`})`
`.then((res) => {`
`console.log(``'ok'``)`
`// console.log(res)`
`})`//歡迎加入全棧開發交流圈一塊兒學習交流:864305860
`.``catch``((err) => {`//幫助突破技術瓶頸,提高思惟能力
`console.log(``'err'``)`
`})`
複製代碼
使用axios或者requst這種底層庫的好處是,你用curl作的成功的任何操做,均可以轉換成axios或request的請求,而不依賴與其餘庫。app