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

标签 node.js

我是服务器端编程新手,在尝试增强 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 npm@5.6.0
3 info using node@v8.10.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle blog-server@1.0.0~prestart: blog-server@1.0.0
6 info lifecycle blog-server@1.0.0~start: blog-server@1.0.0
7 verbose lifecycle blog-server@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle blog-server@1.0.0~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 blog-server@1.0.0~start: CWD: C:\Users\z\Desktop\Allen's-Blog\blog-server
10 silly lifecycle blog-server@1.0.0~start: Args: [ '/d /s /c',
10 silly lifecycle   'egg-scripts start --daemon --title=egg-server-blog-server' ]
11 silly lifecycle blog-server@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle blog-server@1.0.0~start: Failed to exec start script
13 verbose stack Error: blog-server@1.0.0 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 blog-server@1.0.0
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 blog-server@1.0.0 start: `egg-scripts start --daemon --title=egg-server-blog-server`
22 error Exit status 1
23 error Failed at the blog-server@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

最佳答案

使用此命令:console.log( <The variable you want to debug> );当你想要调试某些东西时,

经验:

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

还有很多其他调试工具和 IDE 也可以为您提供帮助(我推荐使用 VSCode,它易于使用并且具有不错的功能)。

关于node.js - 如何从日志消息调试node.js程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55742409/

相关文章:

node.js - 了解 Error.captureStackTrace 和堆栈跟踪持久性?

javascript - 有时 Handlebars 不加载对象

javascript - 如何将我的 node.js 文件合并到 postman 请求中?

javascript - 在 Angular 中从服务器下载文本/csv 内容作为文件

javascript - 如何从选项列表中获取一项

arrays - 如何为 NodeJS 创建一个返回带有动态键名的数组的函数?

html - 如何使用 node.js 将 CSS 和 Bootstrap 文件加载到服务器?

javascript - 基于名称属性的对象数组排序错误

c# - 在 Azure 上,Web api+Azure AD 或expressjs+passportjs

node.js - Gulp 执行但什么也不做