???
Wait, so what's the solution?
Wait, so what's the solution?
$ node -e "const { Stream } = require('stream'); s = process.stdout; s.write('@'.repeat(128 * 1024)); Stream.finished(s, () => { process.exit(0); })" | wc -c
131072
https://nodejs.org/api/stream.html#streamfinishedstream-opti...See also `process.on('exit', ...)`; you can conditionally set process.exitCode in it (only if there was no other failure) if you want.
$ node -e "fs.writeFileSync(1, Buffer.from('@'.repeat(128 * 1024))); process.exit(0);" | wc -c
131072(If blocking the process on writing synchronously to stdout is indeed what you actually want...)