节点在作为"node --debug-brk"启动时不会在第一行中断



以下文件作为节点启动——debug brk hello http.js

你好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 Worldn");
});
// 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/");

在第一行,程序预计会中断,直到使用节点检查器(在另一个终端上运行)发出continue命令为止,最后一行console.log("服务器在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/

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

更新1:

重新启动机器后

  1. 节点--debug brk hello http.js等待调试器连接为显示的

    $node--调试brk hello-http.js调试器侦听端口5858

  2. 节点检查器正盯着另一个终端

  3. chrome浏览器连接到节点检查器时http://127.0.0.1:8080/debug?port=5858节点程序继续执行(打印运行于http://127.0.0.1:8000),而没有等待调试器发送命令。

    $node--调试brk hello-http.js调试器正在侦听端口5858服务器运行于http://127.0.0.1:8000/

这是意料之中的事吗。如果是,如何让节点检查器发送断点命令,在第一行设置断点。

看起来就像node-inspector中的一个bug。

https://github.com/node-inspector/node-inspector/issues/534

当在Node(0.12,1.x)的v0.10后版本上运行时,这是节点检查器的已知问题,请参阅https://github.com/node-inspector/node-inspector/issues/534.

最新更新