0
router.get('/test', function(req, res, next) {
    res.write("start\n");

    setTimeout(()=>{
        res.write('5 seconds later?');
        res.end();
    }, 5000);
});

Basically I just want to send my data in parts to the browser, but it seems to just hold all the data until it gets to res.end, then sends it all at once.

I tried all the answers in this thread: How can I output data before I end the response?

but they still all seem to just wait until the end and send it all at once.

Is there an update on how to accomplish this?

stackers
  • 2,701
  • 4
  • 34
  • 66
  • could you describe your use case generally where you would need to do this? – BEvo Nov 24 '20 at 20:46
  • sending updates on a long process to the user (which would be an admin, so it's fine that it's just text) – stackers Nov 24 '20 at 21:19
  • what you could possibly do is define chunks in your back end and initiate multiple requests sequentially from the front end, where each asks the back end for one of these chunks. This would essentially achieve the same. – BEvo Nov 24 '20 at 21:43
  • was hoping for something with a simple set up – stackers Nov 24 '20 at 22:45
  • What is the client you're using for this? Chances are, your client is not reporting anything to you until it has all arrived even though pieces of it have arrived long before. – jfriend00 Nov 25 '20 at 01:24
  • FYI, `res` is a stream and it sends data as soon as you pause from sending. The usual issue is using a client that actually recognized incremental packets as they arrive rather than holding them all until the response is done an only tell you then. – jfriend00 Nov 25 '20 at 03:10

0 Answers0