How to create a Node.js API that can send progress

2019-08-19 05:58发布

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?

2条回答
你好瞎i
2楼-- · 2019-08-19 06:30

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.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-08-19 06:35

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.

查看更多
登录 后发表回答