如何从日志消息调试node.js程序

问题描述 投票:2回答:1

我是服务器端编程的新手,在尝试提升node.js程序(egg.js框架)时收到了一些错误消息

由于我的某些代码行,例如“undefined var xx”,我不是那种错误,我只是不知道如何从这些消息中调试它

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\node\\node.exe',
1 verbose cli   'C:\\nvm\\nvm\\node_global\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 info lifecycle [email protected]~start: [email protected]
7 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~start: PATH: C:\nvm\nvm\node_global\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\z\Desktop\Allen's-Blog\blog-server\node_modules\.bin;C:\Users\z\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\z\bin;C:\Program Files\ImageMagick-7.0.6-Q16;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Python27;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Java\jdk1.8.0_171\bin;C:\Program Files\Java\jdk1.8.0_171\jre\bin;D:\Software\gradle\bin;C:\nvm\nvm;C:\node;C:\nvm\nvm\node_global;C:\Program Files\Git\cmd;C:\Program Files\PuTTY;C:\Program Files\TortoiseSVN\bin;C:\Program Files\MongoDB\Server\4.0\bin;C:\Program Files (x86)\SMLNJ\bin;C:\Users\z\AppData\Local\Programs\Python\Python35\Scripts;C:\Users\z\AppData\Local\Programs\Python\Python35;C:\Ruby24-x64\bin;C:\Users\z\AppData\Local\Microsoft\WindowsApps;node_global;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\nvm\nvm;C:\node;D:\Software\fiddle\Fiddler;D:\projects\Microsoft VS Code\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
9 verbose lifecycle [email protected]~start: CWD: C:\Users\z\Desktop\Allen's-Blog\blog-server
10 silly lifecycle [email protected]~start: Args: [ '/d /s /c',
10 silly lifecycle   'egg-scripts start --daemon --title=egg-server-blog-server' ]
11 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
12 info lifecycle [email protected]~start: Failed to exec start script
13 verbose stack Error: [email protected] start: `egg-scripts start --daemon --title=egg-server-blog-server`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\nvm\nvm\node_global\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\nvm\nvm\node_global\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd C:\Users\z\Desktop\Allen's-Blog\blog-server
16 verbose Windows_NT 10.0.17134
17 verbose argv "C:\\node\\node.exe" "C:\\nvm\\nvm\\node_global\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v8.10.0
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] start: `egg-scripts start --daemon --title=egg-server-blog-server`
22 error Exit status 1
23 error Failed at the [email protected] start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
node.js
1个回答
0
投票

使用此命令:console.log( <The variable you want to debug> );何时要调试某些内容,

Exp:

var arr = [1,2,3,4,5];
for (let i in arr){
  console.log(i);
}

还有很多其他调试工具和IDE也可以帮助你(我建议使用VSCode,它易于使用并具有不错的功能)。

© www.soinside.com 2019 - 2024. All rights reserved.