how to increase nodejs default memory?

后端 未结 4 1114
甜味超标
甜味超标 2020-12-03 13:30

On Server startup exporting 2GB(Approximately) data from mongodb to redis,then getting error as FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of mem

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 13:46

    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.

提交回复
热议问题