Docs / Troubleshooting / How to Fix Node.js ENOMEM Out of Memory Errors

How to Fix Node.js ENOMEM Out of Memory Errors

By Admin · Mar 1, 2026 · Updated Apr 23, 2026 · 27 views · 2 min read

Fixing Node.js ENOMEM Out of Memory Errors

Node.js applications crashing with ENOMEM or "JavaScript heap out of memory" errors on your Breeze indicate the process has exceeded its available memory. This guide covers both V8 heap limits and system-level memory issues.

Identify the Error Type

There are two distinct memory problems:

  • V8 Heap Limit -- "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory"
  • System ENOMEM -- the Linux kernel killed the process via the OOM killer

Increase the V8 Heap Limit

Node.js defaults to approximately 1.5 GB heap on 64-bit systems. Increase it:

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

Or set it via environment variable:

export NODE_OPTIONS="--max-old-space-size=4096"
node app.js

Check System Memory

free -h
dmesg | grep -i "out of memory"
journalctl -k | grep -i oom

Add Swap Space

If your Breeze is running low on physical RAM, add swap as a safety net:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab

Find Memory Leaks

Profile your application to identify the source of excessive memory usage:

node --inspect app.js
# Connect Chrome DevTools to chrome://inspect
# Take heap snapshots to identify growing objects

Best Practices

  • Monitor memory usage with process.memoryUsage() in your application
  • Use streaming APIs instead of loading large datasets into memory
  • Set up process managers like PM2 with --max-memory-restart to auto-restart leaking processes

Was this article helpful?