NodeJS - NodeJS的逐步调试器

f1n*_*1nn 9 debugging stack trace node.js

我正在寻找有效的方法来逐步调试NodeJS服务器代码.此刻我使用了几十个console.log(),这非常困难.完美的工具是允许我检查堆栈中每个变量的值并逐行跟踪我的程序的工具.首选操作系统= MacOS/Linux.可能吗?

Gol*_*den 10

基本上,Node.js是建立在V8之上的,因此它的调试功能也建立在V8的调试功能之上.

V8有一个包含的调试器,可以通过端口5858上的TCP访问.

所以基本上你需要的是一个能够连接到端口5858并讨论V8调试协议的前端.

一种选择是使用node-inspector,它基本上在浏览器中提供调试UI.不幸的是,它只适用于谷歌Chrome和Apple Safari(对我来说没有问题,但可能还有其他人;-)).

另一个选择是使用Eclipse的插件.

而且,最后但并非最不重要的是,Node.js的内置调试器(它总是让我想起MS-DOS edlin)也只是这个TCP调试器的前端,只是一个内置的调试器.

当然,还有更多选择......这三个只是前三个我想到的;-)


小智 3

这个怎么样?

您可以尝试测试Nodeclipse 0.2.0 beta版。

http://www.tomotaro1065.com/nodeclipse/

它将帮助您轻松调试节点应用程序。

生成 Express 项目

Select the [File]-[New]-[Project] menu.
Select [Node]-[Express Project], and push [Next] button.
Enter [Project name], and push [Finish] button.
Run Code Online (Sandbox Code Playgroud)

调试

Open the JavaScript source files that you want to set breakpoints.
Double-click on the ruler at the left end of the line you want to set a breakpoint.
If you want to remove a breakpoint, double-click on the ruler again.
Select the main source file of Node Application on the Project Explorer, 
open the context menu by right-clicking, 
select the [Debug As]-[Node Application] menu.
Run Code Online (Sandbox Code Playgroud)