首页 文章

当作为“node --debug-brk”启动时,节点不会在第一行中断

提问于
浏览
1

以下文件作为 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(“运行在http://127.0.0.1:8000/的服务器”)的continue命令;不应该打印 . 但是一旦节点启动它就不会中断并打印日志 .

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

在ubuntu-12.04 LTS机器上运行 node version v0.12.0 如何在第一行中断(即var http = require('http');) .

UPDATE 1:

重启机器后

  • node --debug-brk hello-http.js 等待调试器显示为已连接

$ node --debug -brk hello-http.js监听端口5858的调试器

  • node-inspector 盯着另一个终端

  • 一旦Chrome浏览器连接 node-inspector http://127.0.0.1:8080/debug?port=5858node 程序就会继续执行(打印 Server running at http://127.0.0.1:8000 )而不等待调试器发送命令 .

$ node --debug-brk hello-http.js监听端口5858上运行的调试器http://127.0.0.1:8000/

这是预期的 . 如果是,则如何使node-inspector发送断点命令以在第一行设置断点 .

2 回答

相关问题