当以"node --debug-brk"启动时,Node在第一行不会中断。

3
以下文件启动命令为node --debug-brk hello-http.js

hello-http.js

// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);

// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");

在程序的第一行,预计会发生中断,直到使用node-inspector(在另一个终端上运行)给出继续命令之前,最后一行console.log("Server running at http://127.0.0.1:8000/");不应该被打印。但是一旦节点启动,它就不会中断并打印日志。

$ node --debug-brk hello-http.js 
Debugger listening on port 5858
Server running at http://127.0.0.1:8000/

使用 node版本v0.12.0 在一台运行ubuntu-12.04 LTS的机器上运行。如何使它在第一行(即var http = require('http');)中断。

更新1:

重新启动机器后

  1. node --debug-brk hello-http.js 等待调试器连接,显示如下:

    $ node --debug-brk hello-http.js Debugger listening on port 5858

  2. 在另一个终端上启动 node-inspector

  3. 一旦 Chrome 浏览器连接到 http://127.0.0.1:8080/debug?port=5858 上的 node-inspectornode 程序将继续执行(打印Server running at http://127.0.0.1:8000),而不必等待调试器发送命令。

    $ node --debug-brk hello-http.js Debugger listening on port 5858 Server running at http://127.0.0.1:8000/

这是预期的吗?如果是,如何让node-inspector发送断点命令以在第一行设置断点。


我无法重现这个问题。你是否有调试器在运行?也许你的调试器正在使它立即执行? - loganfsmyth
重启节点程序后,程序会等待调试器连接。但是一旦node-inspector连接成功,程序就会开始执行而不会在第一行停止。请查看问题中的更新。 - Talespin_Kit
2个回答

4

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接