Node.js / Express.js在RealTime中显示文件更新

时间:2021-12-12 20:56:57

I wanted to know if there was a module in node that was could be use the Express module to display updated information in the browser from the contents of a file.

我想知道节点中是否有一个模块可以使用Express模块​​从文件内容中显示浏览器中的更新信息。

I have a .csv file that is updated and I would like to display the updates in real time over the express page.

我有一个更新的.csv文件,我想在快递页面上实时显示更新。

Is there anything that can do this? Would Meteor.js be a better alternative?

有什么可以做到这一点? Meteor.js会更好吗?

Thanks.

2 个解决方案

#1


1  

What you need is just a persistent connection, with the possibility for the server to "push" data to client, whenever the file change.

您需要的只是一个持久连接,只要文件发生变化,服务器就有可能将数据“推送”到客户端。

  • To push data, Socket.io should do the job. It use Websockets to maintain persistent connection. You just emit a message from node, and on the client side, your Javascript listen to those messages. They can contain any data needed to update the page, with the help of JQuery for example.

    要推送数据,Socket.io应该完成这项工作。它使用Websockets来维护持久连接。您只是从节点发出消息,在客户端,您的Javascript会听取这些消息。例如,在JQuery的帮助下,它们可以包含更新页面所需的任何数据。

  • To watch the .csv file you can use fs.watch() as suggested below.

    要观看.csv文件,您可以使用fs.watch(),如下所示。

#2


0  

You could use fs.watch() (http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener), but it does depend on the system node is running on. With that, you could use websockets to notify anyone 'watching' that file.

您可以使用fs.watch()(http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener),但它确实依赖于正在运行的系统节点。有了它,您可以使用websockets通知任何人“观看”该文件。

I believe that is pretty much what meteor does (haven't used it though, just did a little research on it).

我相信这几乎就像流星一样(虽然没有使用它,只是对它进行了一些研究)。

#1


1  

What you need is just a persistent connection, with the possibility for the server to "push" data to client, whenever the file change.

您需要的只是一个持久连接,只要文件发生变化,服务器就有可能将数据“推送”到客户端。

  • To push data, Socket.io should do the job. It use Websockets to maintain persistent connection. You just emit a message from node, and on the client side, your Javascript listen to those messages. They can contain any data needed to update the page, with the help of JQuery for example.

    要推送数据,Socket.io应该完成这项工作。它使用Websockets来维护持久连接。您只是从节点发出消息,在客户端,您的Javascript会听取这些消息。例如,在JQuery的帮助下,它们可以包含更新页面所需的任何数据。

  • To watch the .csv file you can use fs.watch() as suggested below.

    要观看.csv文件,您可以使用fs.watch(),如下所示。

#2


0  

You could use fs.watch() (http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener), but it does depend on the system node is running on. With that, you could use websockets to notify anyone 'watching' that file.

您可以使用fs.watch()(http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener),但它确实依赖于正在运行的系统节点。有了它,您可以使用websockets通知任何人“观看”该文件。

I believe that is pretty much what meteor does (haven't used it though, just did a little research on it).

我相信这几乎就像流星一样(虽然没有使用它,只是对它进行了一些研究)。