2017-10-11 89 views
0

我有一個express.js項目(打字稿)用下面的命令的package.json的NodeJS - 在express.js項目

"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歲的空間大小,但我不知道在哪裏把它....

我看到的例子是

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(`*******************************************`); 
+0

'NPM start'運行'start'腳本,運行'serve',然後運行'serve'。將服務更改爲'nodemon dist/server.js --max-old-space-size = 4096' – Phix

+0

我已經測試了這個不缺 – Michalis

+0

沒有標誌和你的代碼,我得到了'1.39GB',帶有我得到的標誌'0.02GB',所以它正在做一些事情。 – Phix

回答

0
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)