How to debug a basic node.js application (not http

2019-01-30 03:05发布

I know how to debug http applications using node-inspector and iisnode. But can I use node-inspector to debug a non http node application, on windows?

I tried:

 node debug test.js

It says:

debugger listening on port 5858

But opening http://localhost:5858/ in Chrome does not do anything.


BTW: running node debug test.js does start the command-line debugger which works. But it's nothing like node-inspector.

7条回答
Melony?
2楼-- · 2019-01-30 04:06

To use node-inspector, the right switch is node --debug not node debug

Here are the detailed steps:

  1. install node-inspector globally (npm install -g node-inspector)
  2. from a command-line window, run: node-inspector
  3. open Chrome and go to http://localhost:8080/debug?port=5858. You'll get the node-inspector UI but without any running app.
  4. from another command-line window, run your app with the --debug switch like this: node --debug test.js
  5. refresh the Chrome tab and voila!

A few interesting points:

  • If you kill your app and start it again, just refresh the node-inspector tab. It will keep all your breakpoints.
  • To break automatically on the first line start your app with node --debug-brk test.js
查看更多
登录 后发表回答