how to increase nodejs default memory?
Solution 1:
node SomeScript.js --max-old-space-size=8192
- Where SomeScript is the file name that you want to execute using node.
Solution 2:
one option: npm start scripts
https://docs.npmjs.com/misc/scripts
These are added to your package.json under the "scripts" section
{
//other package.json stuff
"scripts":{
"start": "node --max-old-space-size=4076 server.js"
}
}
then to run it call npm start
instead of typing in node + args + execution point.
Note: if you name it something other than start, npm run [yourScriptNameHere]
will be the command to run it
This is a better option than trying to reconfigure node to use 4gb by default (don't even know if its possible tbh). It makes your configuration portable by using the baked in methods as it stands and allows others who encounter your code in the future to understand this is a need.
Solution 3:
You can also set NODE_OPTIONS
when running an npm script rather than node
itself:
"scripts": {
"start": "NODE_OPTIONS=--max-old-space-size=4096 serve",
},
Solution 4:
There are two ways to resolve this, First way is to set memory size explicitly for your application, already answered above. And the other way is to set memory size globally for node - This is done by creating an Environment variable, with
variable name=NODE_OPTIONS
and
variable value=--max-old-space-size=4096