Early flush with Node.js and Express [duplicate]

我与影子孤独终老i 提交于 2019-12-13 00:33:38

问题


How do I realise early flush (chuncked transfer encoding) with Express?

All examples I have found are dealing with the http module, where you can call the write() method of the response object and that way send data piece-wise.


回答1:


You can still use write with Express:

app.get('/test', function(req, res) {
  var count     = 0;
  var interval  = setInterval(function() {
    if (count++ === 5) {
      clearInterval(interval);
      res.end();
    }
    res.write('This is line #' + count + '\n');
  }, 1000);
});


来源:https://stackoverflow.com/questions/20937621/early-flush-with-node-js-and-express

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