How can I pipe a file without having buffer build up in Node.JS?

I'm using Node.JS to proxy a file upload to a remote endpoint and need to make sure my Node server doesn't buffer the file excessively.

I'm using res.write to push in the following way:

apiRes.on('data', function (chunk) {
    body += chunk;
    res.write(chunk);
});

(The connection is faster from client to node than from node to the remote).

Note that the client is a browser, if that wasn't clear.

Node.js API Docs

apiRes.pipe(res);

  • use xhr.send file with the help of FileReader.
  • use apiRes.pipe(res) as suggested by Dream707