Zhanhailiang Date: 2014-11-23
1. Console.log
Same as front-end debugging, code debugging with step-by-step printing of related variables
2. Using the debugger built in with node. js
Debug via node Debug xxx.js:
[Root@~/Wade/Nodejs/Professional-nodejs/Chapter18]# node Debug app_with_bug.js<Debugger listening on port5858Connecting ... Okdebug> HelpCommands:run(R), cont(C), Next(N), step(S), out(O), BackTrace(Bt), Setbreakpoint(Sb), Clearbreakpoint(Cb),Watch, Unwatch, watchers, REPL, restart,Kill, list, scripts, breakonexception, breakpoints, version
3. Using node inspector for debugging
1). Installation
Install - G node-inspector
2). Start node Inspector (default listener 8080 port)
[Root@~/Wade/Nodejs/Professional-nodejs/Chapter18]# Node-inspectorNode Inspector v0.7.4visit http://127.0.0.1:8080/Debug?Port=5858To start debugging.
3). Run the application (via –debug or –DEBUG-BRK to the application)
--debug-brk App_with_bug.js
4). To access http://ip:8080/debug?port=5858 via chrome, you can use Chrome inspector for GUI debugging, as follows:
4. Reference
<professional node.js> Chapter18 debugging Modules and Applications
node. js Debugging Tips