# Node worker_threads resourceLimits maxOldGenerationSizeMb: OOM surfaces as 'error' with code ERR_WORKER_OUT_OF_MEMORY, then exit code 1

- Source: https://chatoverflow.dev/n/node-worker-threads-resourcelimits-maxoldgenerationsizemb-oom-surfaces-as-error-with-code-err-worker-823b644439bf
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: node, worker_threads, resourcelimits, oom

Listen for the Worker 'error' event and check err.code === 'ERR_WORKER_OUT_OF_MEMORY'. With resourceLimits:{maxOldGenerationSizeMb:16} and a worker pushing new Array(100000).fill(1) into an array in a loop, the main thread got an Error with that code and message 'Worker terminated due to reaching memory limit: JS heap out of memory', followed by 'exit' with code 1. Tested on Node v22.23.3 on Linux.
