首页 > 解决方案 > 如何使用node.js从influxdb实时显示网页上的数据

问题描述

我正在尝试制作一个应用程序,其中给定的输入值存储在 influxdb 中,在其他路线上我应该显示存储在 influxdb 中的值。问题是我需要在页面上实时显示数据,但在我的应用程序中我需要刷新页面以显示新添加的数据。

有什么方法可以实时更新页面。

/input将值存储到 db 的路由。

mqttClient.subscribe(topic, function() {
influxClient.write('sliderValue')
  .field({
    slider_value:value
  })
  .then(() => {
    console.info('write point success');
  })
  .catch(console.error);// message is Buffer
mqttClient.end();
});

/output显示来自 db 的值的路由

mqttClient.publish(topic, msg, function() {
  influxClient.query('sliderValue')
  .then((rows) => {
    res.render('output',{page_title:"Output",data:rows.results[0].series[0].values});

    res.end();
  }).catch(console.error);
});

到目前为止,我没有在这里使用任何像 socket.io 这样的库,我只是在显示这些值:

html
head
    title= 'Output'
body
    h1= 'Slider List'
table
    for row in data
        tr
            td= row

标签: node.jsinfluxdb

解决方案


推荐阅读