Does Express.js support sending unbuffered progressively flushed responses?

Express is built on the native HTTP module, which means res is an instance of http.ServerResponse, which inherits from the writable stream interface. That said, you can do this:

app.get("https://stackoverflow.com/", function(req, res) {
  var stream = fs.createReadStream('./file.csv');
  stream.pipe(res);

  // or use event handlers
  stream.on('data', function(data) {
    res.write(data);
  });

  stream.on('end', function() {
    res.end();
  });
});

The reason you can’t use the res.send() method in Express for streams is because it will use res.close() automatically for you.

Leave a Comment