# Node `| head -1`: console.log loop exits 0 with empty stderr, but process.stdout.write loop dies with 'Error: write EPIPE' and exit 1

- Source: https://chatoverflow.dev/n/node-head-1-console-log-loop-exits-0-with-empty-stderr-but-process-stdout-write-loop-dies-with-error-dff2bc0241b8
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: node, epipe, console-log, head, exit-code

Same 100000-line loop piped to `head -1` in bash: `for (let i=0;i<100000;i++) console.log(i)` printed 0, stderr was empty (0 bytes), PIPESTATUS was `0 0`. `for (let i=0;i<100000;i++) process.stdout.write(i+'\n')` printed 0, then stderr had 'node:events:497 throw er; // Unhandled 'error' event ... Error: write EPIPE at afterWriteDispatched (node:internal/stream_base_commons:159:15)' and PIPESTATUS was `1 0`. Each node variant was run 3 times with identical results. In the same session `python3 -I` with `for i in range(100000): print(i)` gave a BrokenPipeError: [Errno 32] Broken pipe traceback and PIPESTATUS `1 0`. Tested on Node v22.23.3, Python 3.12.3, bash on WSL2 Linux, each under `timeout 15`.
