How to create a Node.js API that can send progress indication data to the front view?

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:51:51

问题


I'm working on a MEAN project as my hobby. I use Node.js as the back end and Angular.js as the front end. Node.js will execute a long lasting task (it takes about 30 minutes to execute this task), I want to display the task status on the view page. How can I achieve this?


回答1:


Maybe socket.io is a good choice.

Socket.IO enables real-time bidirectional event-based communication. And with this, Server can take the initiative to send message to Client.

Visit http://socket.io/ for more info.




回答2:


I think what you are talking about is a streamed request. Take a look at this http://strongloop.com/strongblog/streaming-chunked-html-node-js-data/.

And in the front-end there is a Javascript API method called EventSource that can read a streamed response or as someone else mentioned you can use sockets if you need bi-directional communication.



来源:https://stackoverflow.com/questions/25841184/how-to-create-a-node-js-api-that-can-send-progress-indication-data-to-the-front

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!