Nodejs - 在express.js项目中增加堆大小

时间:2017-10-11 20:06:25

标签: node.js express v8

我有一个express.js项目(typescript),其中包含以下命令to package.json

"scripts": {
    "start": "npm run build && npm run watch",
    "build": "npm run build-ts && npm run tslint",
    "serve": "nodemon dist/server.js",
    "watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run serve\"",
    "test": "jest --forceExit",
    "build-ts": "tsc",
    "watch-ts": "tsc -w",
    "tslint": "tslint -c tslint.json -p tsconfig.json",
    "debug": "npm run build && npm run watch-debug",
    "serve-debug": "nodemon --inspect dist/server.js",
    "watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-ts\" \"npm run serve-debug\"",
    "angular-build": "cd app && ng build --prod --output-path=../dist/app/ --deploy-url= --no-progress --aot true"
},

我知道增加堆内存大小的命令是--max-old-space-size但我不知道放在哪里....

我看到的所有例子都是

node --max-old-space-size=4096 myapp.js

但我没有以这种方式运行我的应用程序...我只是运行“npm start”

我使用此代码检查当前堆大小

let v8 = require("v8");
let totalHeapSizeInGB = (((v8.getHeapStatistics().total_available_size) / 1024 / 1024 / 1024).toFixed(2));
console.log(`*******************************************`);
console.log(`Total Heap Size ~${totalHeapSizeInGB}GB`);
console.log(`*******************************************`);

2 个答案:

答案 0 :(得分:1)

nodemon --max-old-space-size=4096 dist/server.js (this is OK)
nodemon dist/server.js --max-old-space-size=4096 (this is NOT OK)

答案 1 :(得分:1)

转到你的package.json文件并替换" start"像这样 Screenshot package.json