Node.js - 在 Express.js 项目中增加堆内存大小

3

我有一个使用express.js(typescript)编写的项目,其中包含以下命令添加到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(`*******************************************`);

npm start runs the start script, which runs serve, which then runs serve. Change serve to nodemon dist/server.js --max-old-space-size=4096 - Phix
我已经测试过了,没有任何问题。 - Michalis
没有标志和你的代码,我得到了 1.39GB 的结果,使用标志后我得到了 0.02GB 的结果,所以它正在做某些事情。 - Phix
仍然没有缺…… - Michalis
2个回答

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

0

2
单个外部链接的答案对于SO来说并不是很好。这个想法是使问题完全独立,所以可以提供相关细节的简要概述。 - user1531971

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接