Node.js – Debugging with node-inspector
来源:互联网 发布:java招聘要求本科 编辑:程序博客网 时间:2024/05/29 13:52
本文主要介绍如何使用node-inspector来debug nodejs程序,按照下面的step进行介绍:
- 使用npm安装node-inspector (npm install node-inspector)
- 启动node-inspector (node-inspector &)
- 通过--debug执行nodejs (node --debug example.js)
- 在chrome中输入http://127.0.0.1:8080,打开的tab我们称其为debug tab (firefox不支持)
- 在Scripts里面找到你的nodejs程序,设置断点(这个和在eclipse设置断点相同,点击行最左侧位置即可)
- 在chrome里打开另外一个tab,然后输入http:127.0.0.1:8234, 这个tab我们称其为trigger tab(注意要开启新的tab,上面那个地址打开的tab就留着,另外这里输入的端口是你自己程序中listen的端口,要改成自己的port)
- 在debug tab中我们就可以开始单步执行程序、查看各种变量、添加你想监控的变量,堆栈信息等等
- debug结束以后,我们能在trigger tab中看到最后的输出结果
文章来源:http://elegantcode.com/2011/01/14/taking-baby-steps-with-node-js-debugging-with-node-inspector/
node-inspector: https://github.com/dannycoates/node-inspector
Writing unit tests for your code drastically reduces the amount of debugging. This is the case for practically any programming language that you work in. But when the shit hits the fan, having a debugger with some decent features at your disposal is a must. However Node.js doesn’t come with a debugger out of the box. Thankfully there are a couple of debuggers out there like ndb, node-debug and node-inspector, which I’ll going to be demonstrating in this blog post. For this blog I’m going to show you some of the nice capabilities of node-inspector.
Installing node-inspector is actually pretty easy when you have npm installed. Just issue the following command:
Now we can startup node-inspector
which shows the following output if all goes well:
Now that we have node-inspector running, we can start debugging our node.js application in another console:
which outputs the port on which the debugger is listening.
Now you can open Chrome and point it to the following URL:
http://127.0.0.1:8080/
If all goes well, then we’ll get to see some JavaScript source code:
Note that you’ll have to use Chrome or another WebKit based browser for opening node-inspector. I also tried it in Firefox, but the page doesn’t show at all.
You can then select the JavaScript source file that contains the code you wish to debug and add breakpoints like you would normally do in an IDE like Visual Studio.
Now we can start using our application until we hit a breakpoint.
On the right of the page we can add watch expressions, look at the call stack and the current values of the scope variables. In the code window we have the usual suspects like “Step over”, “Step into next function” and “Step out of current function”. We can even do live editing and all of this right in the browser! Tooltips also work as expected.
Another nice feature is the console window that can be shown/hidden below or taking over the entire window by clicking the menu button at the top of the page.
Because I’ve been using version 0.2.3 for developing my very first application using Node.js, I had to install an older version of node-inspector. If you decide to use the latest version of Node.js, you will see that a couple of interesting new features have been added, like heap snapshots. Make sure to watch this short screen cast to get up and running in no time with node-inspector.
Using node-inspector while developing Node.js applications can really save you a lot of grief. It certainly helped me to find a couple of bugs that would otherwise be hard to track down. It’s also a great learning tool if you would like to learn more about how Node.js behaves at runtime.
- Node.js – Debugging with node-inspector
- 使用node-inspector在线调试Node.js
- 利用node-inspector 调试node.js程序
- 使用 node-inspector 调试 Node.js
- 使用node-inspector调试Node.js应用
- Node Inspector 调试 Node.js 程序
- 使用node-inspector调试Node.js应用
- Node.js调试工具之node-inspector
- node.js 调试工具 node-inspector
- 使用node-inspector调试Node.js应用
- node.js调试使用node-inspector
- node-inspector使用方法(调试JS代码)
- coffee在node.js的调试---inspector
- win7下,安装node-inspector调试Node.js
- node-inspector,is a debugger interface for Node.js applications
- node.js 安装cnpm nodemon express pm2 node-inspector
- node.js 调试工具 node-inspector 简要说明
- node-inspector调试node程序
- self.name="object"和name="object"的区别?
- C++中值传递、指针传递、引用传递的总结
- HTTP协议与REST基础介绍(上)
- 4月15日会议交流所想到的
- HTTP协议与REST基础介绍(下)
- Node.js – Debugging with node-inspector
- SSH2 struts2 在线编辑器实现(一)
- 什么是跆拳道?ITF与WTF有什么区别?带级怎么分?
- Java 数据库处理类优化
- 程序员从初级到中级10个秘诀
- ITF跆拳道的24个特尔
- 为什么我们要放弃Subversion
- ITF跆拳道训练注意事项
- 软件天才都是训练出来的