TLDR Web Dev · ARTICLES & TUTORIALS
NODE.JS, PIPES, AND DISAPPEARING BYTES
Summary from the TLDR Web Dev newsletter
Piping large amounts of JSON data from a Node.js command to another command results in truncated output. The issue stems from the asynchronous nature of Node.js's `process.stdout.write` when writing to a pipe on POSIX systems. When the pipe buffer is full, `process.stdout.write` returns false, and further writes are blocked until the pipe is read. The solution involves subscribing to the `drain` event of the `process.stdout` stream to resume writing after the pipe has been filled.