Node.js调试技巧

  作者: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进行界面化调试,如下:


4. 参考

<Professional Node.js> Chapter18 Debugging Modules and Applications

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值