29

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.

Sylvain
  • 19,099
  • 23
  • 96
  • 145

7 Answers7

63

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
Sylvain
  • 19,099
  • 23
  • 96
  • 145
  • With the latest nodeJS on OSX, it seems that "node debug" does the right thing, and "node --debug" doesn't. – Dan Jameson Apr 02 '15 at 02:10
  • According to https://nodejs.org/api/debugger.html the difference of either version is about what node is expected to do: `--debug` will start _some application to be debugged_ and `debug` will start node _to debug some application_. So these are two sides of the same story. – Thomas Urban Oct 03 '15 at 09:50
2

Some links which might help you:

Alfred
  • 60,935
  • 33
  • 147
  • 186
2

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

Hector Correa
  • 26,290
  • 8
  • 57
  • 73
  • Good point about TCP vs HTTP. I know about the command-line debugger but it's really the node-inspector experience I'm looking for. – Sylvain Jul 11 '12 at 18:54
1

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

0

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

Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164
0

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
0

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

Script Kitty
  • 1,737
  • 5
  • 27
  • 47