You can use –max_old_space_size option to set memory size for your node process. It specifies the memory limit in MBs so something like :
➜ node --max-old-space-size=1536 index.js
means the process will have 1.5gb as max memory space allocated. The process will give “out of memory” or allocation error after that limit is exceeded.
You can set the Nodejs options using NODE_OPTIONS environment variable also. You can know about memory, gc and other v8 options by running
➜ node --v8-options
Also https://github.com/nodejs/node/pull/14093 has made it possible for use of _ and – interchangeably while setting the NODE_OPTIONS.
We will see more about the Garbage collection (gc) optimisations that can be done for our process in next post.