how to increase nodejs default memory?

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.


node SomeScript.js --max-old-space-size=8192
  • Where SomeScript is the file name that you want to execute using node.

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",
},

Tags:

Node.Js