Node. js debugging skills, node. js debugging
Author: zhanhailiang Date:
1. console. log
Similar to front-end debugging, code debugging is performed by printing related variables step by step.
2. Use the Node. js built-in Debugger
Debug through node debug xxx. js:
[root@~/wade/nodejs/professional-nodejs/chapter18]# node debug app_with_bug.js < debugger listening on port 5858connecting... 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. Use Node Inspector for debugging
1). Install
npm install -g node-inspector
2) Start Node Inspector (Listening to port 8080 by default)
[root@~/wade/nodejs/professional-nodejs/chapter18]# node-inspector Node Inspector v0.7.4Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
3). Run the application (run the application through-debug or-debug-brk)
node --debug-brk app_with_bug.js
4). Access http: // ip: 8080/debug through Chrome? Port = 5858, now you can use Chrome Inspector for interface debugging, as shown below:
4. Reference
<Professional Node. js> Chapter18 Debugging Modules and Applications