0

I am trying to debug a very simple script using "node-inspector". I tried both following instructions on the repo, which include running "node-debug" and instructions here which include running "node --debug-brk yourApp.js".

The main problem is that neither of the commands "node", "node-debug" or "node-inspector" return any result. They just return silently.

Running "nodejs --debug-brk myScript.js" on the other hand works, but does not seem to have a nice debug GUI. I can connect to it on http://127.0.0.1:5858/ but it is hardly useful for variable inspection.

1 Answer 1

2

Once you've installed node-inspector globally (with npm install -g node-inspector) you can use it to connect to a nodejs process that's been run in debug mode. Try the following steps.

  1. Open two terminal windows
  2. In the first, run your process you'd like to debug with node --debug-brk myscript.js
  3. In the second, run node inspector with node-inspector
  4. In Chrome, visit the following address: http://localhost:8080/debug?port=5858

What you've done here is start node in debug mode (at port 5858 by default), then launch node inspector, which runs its own webserver on port 8080. The URL (the debug?port=5858 part) is telling node-inspector to connect to the node debug process that's on port 5858. Once you're in there, you'll see that your process has stopped on the first line (as instructed to by --debug-brk). You can then set any other breakpoints you'd like, then press the "play" button to start your process running!

Sign up to request clarification or add additional context in comments.

6 Comments

There is a problem: "node --debug-brk myscript.js" does nothing - it just returns.
@DaSh - I don't know if this is required or not, but I first run node-inspector and then I run node --debug --debug-brk myscript.js. Then, connect the browser to the right URL.
@DaSh - in your original question you'd said that nodejs --debug-brk myScript.js runs; have you made any changes since trying that which would have caused a failure?
@jfriend00 - you should not need to start them in any particular order; it will work either way. the important part is when you load the browser: you need to have both node-inspector and your debug-mode application running before visiting the inspector page: that's what actually initiates the connection.
I'm guessing you're on Ubuntu, which already has a node package that is not Node JS. That's why you need to run nodejs to run Node JS programs. Repeat the above steps with nodejs in place of node and it should work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.