Q: express strips newline when reading buffer and returning in response On a GET request, I am reading a file into buffer, then turning that buffer into string using the toString() method, and then returning that data to the client:
new Promise((resolve, reject) => {
  fs.stat(filepath, (err, stats) => {
    if (err) {
      reject(err);
    }
    return resolve(stats);
  });
})
.then(stats => {
  let size = stats.size;
  let startPos = size - config.tailSize;
  startPos = startPos > 0 ? startPos : 0;

  let options = {
    bufferSize: Math.min(size, config.tailSize),
    startPos: startPos,
  };

  return readFile(filepath, options);
})
.then((data) => {
  return res.send(data);
})

function readFile(f, options) {
  return new Promise((resolve, reject) => {
    var size = options.bufferSize;
    var start = options.startPos;
    var buffer = new Buffer(size);
    var fd = fs.openSync(f, 'r');

    fs.read(
      fd,
      buffer,
      0,
      buffer.length,
      start,
      (err, l, b) => {
        fs.closeSync(fd);
        if (err) {
          console.error('Error reading file:', err);
          return reject(err);
        }
        return resolve(b.toString());
      }
    );
  });
}

If I use Postman, the formatting is correct and the lines appear correct, but if I hit the GET url in the browser, it will be returned to me in a single line.
I believe there's something in the header I need to set so that it renders properly in browser? I don't want to write logic to cause proper rendering of html, just want to display the file in the browser.

A: Your browser will be interpreting it as HTML, so newlines so will treated as spaces. Try setting the Content-Type to text/plain with:
res.type('text/plain').send(data);

