以下文件作为 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=5858, node 程序就会继续执行(打印 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 回答
看起来像
node-inspector
中的一个错误 .https://github.com/node-inspector/node-inspector/issues/534
这是在节点(0.12,1.x)的v0.10之后版本上运行时Node Inspector的已知问题,请参阅https://github.com/node-inspector/node-inspector/issues/534 .