我在windows上运行着一个express,主要用websocket实时传输数据。开了一晚上,早上发现报错了。
请问各位这错是啥意思?
以下是npm-debug的内容
0 info it worked if it ends with ok
1 verbose cli [ ‘C:\Program Files\nodejs\node.exe’,
1 verbose cli ‘C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js’,
1 verbose cli ‘start’ ]
2 info using npm@3.10.10
3 info using node@v6.9.4
4 verbose run-script [ ‘prestart’, ‘start’, ‘poststart’ ]
5 info lifecycle app@0.0.0~prestart: app@0.0.0
6 silly lifecycle app@0.0.0~prestart: no script for prestart, continuing
7 info lifecycle app@0.0.0~start: app@0.0.0
8 verbose lifecycle app@0.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle app@0.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;D:\express\app\node_modules.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\nodejs;D:\mysql\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Users\Administrator\AppData\Roaming\npm
10 verbose lifecycle app@0.0.0~start: CWD: D:\express\app
11 silly lifecycle app@0.0.0~start: Args: [ ‘/d /s /c’, ‘node ./bin/www’ ]
12 silly lifecycle app@0.0.0~start: Returned: code: 3 signal: null
13 info lifecycle app@0.0.0~start: Failed to exec start script
14 verbose stack Error: app@0.0.0 start: node ./bin/www
14 verbose stack Exit status 3
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:877:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid app@0.0.0
16 verbose cwd D:\express\app
17 error Windows_NT 6.1.7601
18 error argv “C:\Program Files\nodejs\node.exe” “C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js” "start"
19 error node v6.9.4
20 error npm v3.10.10
21 error code ELIFECYCLE
22 error app@0.0.0 start: node ./bin/www
22 error Exit status 3
23 error Failed at the app@0.0.0 start script ‘node ./bin/www’.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the app package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node ./bin/www
23 error You can get information on how to open an issue for this project with:
23 error npm bugs app
23 error Or if that isn’t available, you can get their info via:
23 error npm owner ls app
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
JavaScript Heap out of memory 大概是在开发模式下 Session 用完了所有内存
我发现问题所在了,我在express中使用了socket.io的库,这个库存在内存溢出问题。
你的内存泄漏了!
那里写着out of memory,,,
来自酷炫的 CNodeMD
是我的问题,代码调整后,问题已经解决了。 之前没有深入理解V8引擎处理内存的机制,导致无法回收资源,看了一遍书(《深入浅出Node.js》)的关于内存机制的章节后,重新写了下方法搞定了。 起初我定义了一个全局变量,让所有的websockets客户端都共用这个对象,导致这个变量变得越来越大,直到触碰了内存1.4G这条线程序直接崩溃。 64位的系统是1.4G,32位的是0.7G。 可以通过命令在启动node程序时来初始化更大的内存,建议有这方面需求的朋友可以看看关于V8内存机制的内容。