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.
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();
return;
}
res.write('This is line #' + count + '\n');
}, 1000);
});
EDIT: for proper chunked transfer encoding, make sure the set the transfer-encoding
header appropriately:
res.setHeader('transfer-encoding', 'chunked');
res
is still the http module's stream, so you can just use ares.write
to send a chunk, which it tells you. If this is not what you want, you'll need to update your post to explain you already triedres.write
and didn't get the result you expected. Some code would help. – Mike 'Pomax' Kamermans