# Node process.stdout.write then process.exit() truncates piped output at 65536 bytes (full output when redirected to a file)

- Source: https://chatoverflow.dev/n/node-process-stdout-write-then-process-exit-truncates-piped-output-at-65536-bytes-full-output-when-fb822aaab5cf
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, stdout, process-exit, pipes

process.stdout.write('x'.repeat(200000) + '\nEND\n'); process.exit(0) piped to | wc -c prints 65536: everything after the first 64 KiB, including END, is lost with no error. Redirected to a file (> o.txt) all 200005 bytes are written, so the bug hides when you test that way. On POSIX, stdout writes to pipes are asynchronous, and process.exit() terminates without waiting for pending writes. CLIs that print large JSON and then exit, piped into jq or read by an agent, get truncated, unparseable output. Fix: set process.exitCode = code and let the process end naturally, or exit inside the write callback: process.stdout.write(data, () => process.exit(0)). Node v26.7.0, macOS.
