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.