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条回答
Evening l夕情丶
2楼-- · 2019-01-30 03:49

node-inspector could be very helpful.

Use it from any browser supporting websockets.

Breakpoints, profiler, livecoding, etc..

http://erickrdch.com/2012/09/debug-a-nodejs-app-with-chrome-dev-tools.html

查看更多
放荡不羁爱自由
3楼-- · 2019-01-30 03:50

FYI, in OSX 10.8, Chrome v26 doesn't seem to work, but Safari 6 does using the same instructions as above and using 0.0.0.0:8080 to conect.

There is another post by Danny Coates somewhere that says to do it in the following order:

  1. Your node process: node --debug (or --debug-brk) my_program.js
  2. Node-inspector: node-inspector
  3. The browser pointed to 0.0.0.0:8080
查看更多
走好不送
4楼-- · 2019-01-30 03:53
仙女界的扛把子
5楼-- · 2019-01-30 03:57

It says: debugger listening on port 5858

I wondered myself about this but since the Node.js documentation indicates that the debugger is accessible via a simple TCP protocol and says nothing about HTTP my guess is that no, it won't be available at _http://localhost:5858.

"V8 comes with an extensive debugger which is accessible out-of-process via a simple TCP protocol" - http://nodejs.org/api/debugger.html

查看更多
老娘就宠你
6楼-- · 2019-01-30 04:00

If you are a noob like me on Windows, and you get 'node-inspector not recognized' or something about windows JScript error... despite global install, adding to PATH, etc. then this may help.

Navigate to C:\Users\urusername\AppData\Roaming\npm

Then run node-debug.cmd or node-inspector.cmd

You should get magical words like

Node Inspector v0.12.7
Visit http://127.0.0.1:8080/?port=5858 to start debugging.
Debugger listening on port 5858

Awesome. If you know of a better solution, please let me know

查看更多
女痞
7楼-- · 2019-01-30 04:03

Very recently Microsoft released the node.js tools for Visual Studio. It has the very comfortable Visual Studio debugging for node.js.

查看更多
登录 后发表回答