Node.js调试技巧

时间:2014-11-24 01:11:11   收藏:0   阅读:259
  作者:zhanhailiang 日期:2014-11-23

1. console.log

跟前端调试相同,通过一步步打印相关变量进行代码调试

2. 使用Node.js内置的调试器

通过node debug xxx.js来进行调试:

[root@~/wade/nodejs/professional-nodejs/chapter18]# node debug app_with_bug.js 
< debugger listening on port 5858
connecting... ok
debug> help
Commands: run (r), cont (c), next (n), step (s), out (o), backtrace (bt), setBreakpoint (sb), clearBreakpoint (cb),
watch, unwatch, watchers, repl, restart, kill, list, scripts, breakOnException, breakpoints, version

3. 使用Node Inspector来进行调试

1). 安装

npm install -g node-inspector

2). 启动Node Inspector(默认监听8080端口)

[root@~/wade/nodejs/professional-nodejs/chapter18]# node-inspector 
Node Inspector v0.7.4
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.

3). 运行应用程序(通过–debug或–debug-brk来启运应用程序)

node --debug-brk app_with_bug.js

4). 通过Chrome浏览器访问http://ip:8080/debug?port=5858,此时即可使用Chrome Inspector进行界面化调试,如下:

bubuko.com,布布扣

4. 参考

<Professional Node.js> Chapter18 Debugging Modules and Applications

原文:http://blog.csdn.net/billfeller/article/details/41423025

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!