EPIPE in Node.js — What It Means and How to Fix It

What the Node.js/npm error EPIPE means and how to resolve it.

Published October 25, 2026

EPIPE means you wrote to a pipe or socket whose other end has closed, for example piping Node output into head.

What it means and why it happens

Typical causes: the reader exited early or a client disconnected before the response finished.

Read the full message: it names the file and line where the problem was detected, which is the best place to start.

What you see

run the code
Error: write EPIPE

Practical examples

Code that triggers it

for (;;) console.log('x')   // | head -1

The fix

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

Handle client disconnects

res.on('close', () => { /* stop work */ })

Common mistakes

  • Not handling stream errors.
  • Continuing to write after close.
  • Ignoring client aborts in HTTP handlers.

Key takeaways

  • EPIPE: EPIPE means you wrote to a pipe or socket whose other end has closed, for example piping Node output into head.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Is it a bug?

Often harmless: the reader simply stopped listening.

How do I find which line caused EPIPE?

The error message and stack trace show the file and line; start there and work backwards.

More JavaScript articles