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

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

Published October 26, 2026

ECONNRESET means the other side abruptly closed the connection while you were reading or writing.

What it means and why it happens

Typical causes: server crashes or restarts, idle timeouts on load balancers, or reusing stale keep-alive connections.

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: read ECONNRESET

Practical examples

Code that triggers it

await fetch(url)   // server drops the connection

The fix

for (let i = 0; i < 3; i++) { try { return await fetch(url) } catch (e) { if (e.cause?.code !== 'ECONNRESET') throw e } }

Tune keep-alive

new http.Agent({ keepAlive: true, keepAliveMsecs: 10000, timeout: 30000 })

Common mistakes

  • No retry logic.
  • Keep-alive longer than the server's idle timeout.
  • Ignoring errors on sockets.

Key takeaways

  • ECONNRESET: ECONNRESET means the other side abruptly closed the connection while you were reading or writing.
  • Read the message and the line number first.
  • Fix the cause, don't just silence the error.

FAQ

Client or server?

Either; check logs on both sides and proxy timeouts.

How do I find which line caused ECONNRESET?

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

More JavaScript articles