How to limit CPU and memory usage for node processes

From node v8+, typing the following:

node --help

show a --v8-options option. Then typing:

node --v8-options

gives:

...
--max_old_space_size (max size of the old space (in Mbytes))
    type: int  default: 0
--initial_old_space_size (initial old space size (in Mbytes))
    type: int  default: 0
...

I have managed to use the first option like this:

node --max-old-space-size=250 `which npm` install

Here we told node to limit RAM usage to 250Mo, the 'which npm' part gives the current npm path and 'install' is the script you want to run.


This is how you do it.

You send a command to limit the ram usage.

npm install --max-old-space-size=400