I\'ve been trying to get a express app to send the response as stream.
var Readable = require(\'stream\').Readable;
var rs = Readable();
app.get(\'/report\
I was able to get this to work.
...
router.get('/stream', function (req, res, next) {
//when using text/plain it did not stream
//without charset=utf-8, it only worked in Chrome, not Firefox
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.setHeader('Transfer-Encoding', 'chunked');
res.write("Thinking...");
sendAndSleep(res, 1);
});
var sendAndSleep = function (response, counter) {
if (counter > 10) {
response.end();
} else {
response.write(" ;i=" + counter);
counter++;
setTimeout(function () {
sendAndSleep(response, counter);
}, 1000)
};
};