4

我有一个我正在尝试调试的基本 express 应用程序,但我无法让节点检查器在 OSX 上正常工作

在一个终端窗口中,我运行:

node --debug-brk server.js

在另一个终端窗口中,我运行:

node-inspector

节点检查器在此处打开:

http://localhost:8080/debug?port=5858

在另一个浏览器选项卡中,我尝试在此处打开我的网站

http://localhost:8080/

我被打印到屏幕上

Cannot GET /

如果我改为打开

http://localhost:3000

我得到了我的应用程序,因为我在 server.js 中设置了它

app.set('port', process.env.PORT || 3000);

但是现在在调试器中没有一个断点可以工作

我确信我在这里做了一些愚蠢的事情,但是我一遍又一遍地阅读了文档和教程,但我无法让它工作。

我尝试过的另一件事是在一个终端窗口中运行:

node-debug server.js

我得到和上面一样的东西。调试检查器打开并在第一行停止,我的站点位于

http://localhost:8080

仍然说

Cannot GET /

我也试过

node-debug --no-debug-brk server.js

我得到了相同的结果,除了节点检查器没有在第一行停止

4

1 回答 1

1

Debug inspector opens and is stopped at first line...

When node-inspector starts debugging an application, by default, it stops at the first line, during the app starting process. If you try to access your app at http://localhost:3000 with the debugger stopped at the first line, you'll never get to your breakpoints.

Before trying anything, you must resume script execution or start node-inspector with the --no-debug-brk option, to prevent stopping at the first line.

To make sure node-inspector is not stopping at any line at all, what you should do:

  • put a breakpoint at the line where you have your app.listen call, or;
  • a more extreme solution: put a breakpoint at every line of your main file.
于 2014-08-30T17:55:16.353 回答