Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

debugging - How to PROPERLY debug node.js with node inspector?

I have an app built in node.js and I use the node inspector in order to debug. But it's quite hard because of this:

  1. My breakpoints are never saved after I restart the server
  2. I cannot put a breakpoint on a file that has not loaded yet; so I have to step into from the first script to the one I want; REALLY PAINFULL!

How do you really debug node.js with node inspector?

The videos on how to use node.js are quite misleading as everything is into a module...
http://www.youtube.com/watch?v=AOnK3NVnxL8

or this one the scripts appear are already loaded in the first script
http://www.youtube.com/watch?v=HJOH0-g8f6E&feature=mfu_in_order&list=UL

Edit:

Nobody can answer this question? :s

question from:https://stackoverflow.com/questions/8882927/how-to-properly-debug-node-js-with-node-inspector

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In javascript you can set breakpoints using the debugger; statement. However, they will only pause node if a debugger is actually attached.

So launch your node script using

node --debug-brk myfile.js

then launch node-inspector and press the play button to continue to the next breakpoint and it will hit your debugger; breakpoint (at least that works for me ATM)

(as noted in the comments: in recent versions of node you no longer have to separately install node-inspector. If you launch node using node --debug-brk --inspect myfile.js you get a url that launches the debugger in your browser).

you still need one extra click after restarting, but at least your breakpoints are saved.

if your breakpoint is not hit automatically, but only after some user action you don't need the --debug-brk of course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...