Node.js Express process exits silently when parsing very large JSON payloads — signs of V8 heap exhaustion
Environment
Node.js 18.x running Express 4 on a 16‑GB RAM server under PM2; POST /import endpoint accepts JSON arrays produced by client tools. Some clients upload single JSON payloads hundreds of megabytes to multiple GB.
Symptoms
When a client posts a very large JSON payload, the Node process exits abruptly without an application stack trace; process manager shows exit code 1 and immediate restart. Smaller payloads succeed. No explicit 'out of memory' message written by application code.
Observations
Monitoring shows process memory climbs rapidly toward the V8 heap limit and CPU spikes from GC before the crash. Running Node with --trace-gc shows prolonged GC activity prior to exit. Replacing JSON.parse with a streaming JSON parser reduces memory usage and prevents crashes for the same test payload. Logs show the default bodyParser in Express buffered the entire payload into memory.
Already attempted
Increased --max-old-space-size to 8192, increased Express bodyParser limit to allow larger bodies, implemented a streaming parser (stream-json) in a test route which successfully processed the large payload, configured reverse proxy (nginx) client_max_body_size higher to avoid proxy rejection. However, simply increasing memory still risks OOM under concurrent uploads.
Question
What are safe server-side patterns to handle very large JSON uploads in Node.js/Express to avoid process crashes, and which immediate mitigations should I apply to protect the server while implementing a streaming solution?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags