NodeJs Debugging
Debugging
The essentials
- Reproducibility
- Reduction
- Experimentation
- Experience
- Tenacity
Techniques
- Interactive
- Print (or tracing)
- Remote
- Post Mortem
- Wolf fence algorithm
- Delta debugging
- Saff Squeeze
Debugger
a program that is used to test and debug other programs (the "target" program)
Comparing Node.js Debug Options
-
Built-in Debugger
-
Node Inspector
-
IDE Debuggers
1. Built-in Debugger
"debugger" statement
run your app in debug mode via:
node debug [your app]
setBreakpoint() – sb()
setBreakpoint(line) – sb(line)
clearBreakpoints() – cb()
repl , watch(expression)
continue – cont, c
step – next, n
step in – step, s
step out – out, o
node debug -p <pid> - Connects to the process via the pid
node debug <URI> - Connects to the process via the URI such as localhost:5858
run your app in debug mode via:
node --debug [your app]
Attach Debugger
2. Node Inspector
Node Inspector allows you to use the DevTools user interface with the native Node debugger
npm install -g node-inspector
node-debug app.js
Problem:
The built-in Node debugger uses a protocol called V8-Debug
while DevTools uses the Chrome Debugging Protocol
Solution:
V8 Inspector Integration in Node.js v6.3+
node --inspect app.js
node --inspect=9222 app.js
3. IDE Debuggers
VS Code has built-in debugging support for Node.js runtime
Once you have found the bug
"Never leave an enemy at your back"
Book to read
https://7chan.org/pr/src/debugging_-_the_9_indispensable_rules_for_finding_.pdf
Thankyou
deck
By Ammar Hasan
deck
- 515