node.js - 如何使用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
解决方案
推荐阅读
- wordpress - Woocoomerce - 将类添加到输入标签
- node.js - nodejs request.post 无法获取cookies,但是request.get 是可以的。
- apache - 使用 WampServer 拒绝访问网络上另一台计算机上的端口 443 (https://)
- r - 重新排序,排除一列并将其他列保留在 R 中?
- c# - WPF 双向绑定 DataGrid 中的 WinForms 控件
- java - Spring Boot Startup 卡在 - INFO: Using a shared selector for servlet write/read
- typescript - 如何将类的所有属性传递给父构造函数类?
- c - C结构,具有不同位大小的变量
- android - 错误:找不到符号方法注入(TestApplication)
- css - 在 React 中设置正文背景颜色