In Node.js, the –max-old-space-size flag is used to increase the maximum heap memory limit for your application.

What is –max-old-space-size?

  • Node.js has a default memory limit (~512 MB for 32-bit, ~1400 MB–2 GB for 64-bit).
  • For memory-heavy apps (e.g. data processing, large builds), you can increase this limit.

Usage Syntax
node --max-old-space-size=4096 your_script.js

This sets the max memory limit to 4096 MB (4 GB).

Examples

1. Run a Node script with 4GB memory:

node --max-old-space-size=4096 server.js

2. Increase memory in npm/yarn scripts:

In package.json:
"scripts": {
"start": "node --max-old-space-size=4096 index.js"
}

Or with build tools:
NODE_OPTIONS="--max-old-space-size=8192" npm run build

How It Works

  • The “old space” is where long-lived objects are stored in the V8 heap.
  • By increasing it, you give your app more room for objects and garbage collection, reducing JavaScript heap out of memory errors.

Check Current Limit (in code)

console.log(v8.getHeapStatistics());

Add this after:

const v8 = require('v8');

Need Help With Node Development?

Work with our skilled Node developers to accelerate your project and boost its performance.

Hire Node.js Developers

Support On Demand!

Related Q&A