Nodejs - 增加 express.js 项目中的堆大小
Nodejs - Increase heap size in express.js project
我有一个 express.js 项目(打字稿),其中包含 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(`*******************************************`);
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)
转到您的 package.json 文件并像这样替换 "start"
Screenshot package.json
我有一个 express.js 项目(打字稿),其中包含 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(`*******************************************`);
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)
转到您的 package.json 文件并像这样替换 "start" Screenshot package.json