EPIPE 🟩 Node.js

Error: write EPIPE

Node wrote to a pipe or socket whose other end was already closed.

Seen on: Node.js

Meaning

Piping output to a command that exits early (head, grep -q), clients disconnecting mid-response, or child processes that died.

Common causes

  • Downstream process closed stdin (e.g. node script.js | head)
  • Client disconnected during a stream
  • Child process exited before you wrote to it

⚡ Quick fix

  1. Handle the stream ‘error’ event
  2. Ignore EPIPE on stdout when piping to head
  3. Check the child process is alive before writing

Detailed fix by platform

Node.js

  1. process.stdout.on('error', e => { if (e.code === 'EPIPE') process.exit(0); });

How to diagnose

  1. Writer — Which stream?
  2. Reader — Why did it close?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.