Node.js "Reached Heap Limit": FATAL ERROR Fix

Symptom

FATAL ERROR: Reached heap limit — Allocation failed - JavaScript heap out of memory.

Root cause

V8 heap (default ~4GB on 64-bit) exceeded — leak or genuinely big workload.

Fix, in order

1. Raise the ceiling only as a stopgapnode --max-old-space-size=8192 server.js
2. Prove it is not a leak with a heap snapshotnode --heap-prof # then open in Chrome DevTools
3. Stream big files instead of loading themcreateReadStream / pipeline # not readFile on 2GB JSON
4. Offload CPU-heavy workconst { Worker } = require("worker_threads")

Prevent it coming back

Load-test before shipping; alert on RSS growth slope.

Run it on clean infra

Spinning up a fresh box to reproduce or escape this error?

Servers with headroom

Related

Cloud & DevOps tool comparisons · Hardware build guides

NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.

Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog