Joe Karlsson
progress. tech. cats. coffee. art. food. photog. mpls.
node debug app.js
function floop (i) {
if (i > 0) {
var decrementer = 10;
while( decrementer-- > 0 ){
i--;
}
floop(i);
}
return i;
}
floop(50);
node debug app.js
< Debugger listening on port 5858
connecting to port 5858... ok
break in app.js:12
10 }
11
>12 floop(50);
13 });
debug>
debug> s
break in app.js:2
1 function floop (i) {
> 2 if (i > 0) {
3 var decrementer = 10;
4 while( decrementer-- > 0 ){
press s to step into the function
debug> repl
Press Ctrl + C to leave debug repl
> i
50
> i = 20;
20
> i
20
launch a repl using the command repl
ctrl + c goes back to debugging console
press s to continue stepping through
with the new value of i being 20
debug> watch("decrementer");
watch("expr") unwatch("expr")
debug> s
break in app.js:3
Watchers:
0: decrementer = undefined
1 function floop (i) {
2 if (i > 0) {
> 3 var decrementer = 10;
4 while( decrementer-- > 0 ){
5 i--;
Step in
and the expression "decrementer" will be watched
debug> s
break in app.js:4
Watchers:
0: decrementer = 10
2 if (i > 0) {
3 var decrementer = 10;
> 4 while( decrementer-- > 0 ){
5 i--;
6 }
Keep stepping through and notice the watched epression
debug> s
break in app.js:5
Watchers:
0: decrementer = 9
3 var decrementer = 10;
4 while( decrementer-- > 0 ){
> 5 i--;
6 }
7 floop(i);
Keep stepping through and notice the watched epression
unwatch("decrementer")
Set breakpoint on current line setBreakpoint()
Set breakpoint on specific line setBreakpoint(line #)
Set breakpoint on the first statement in function setBreakpoint('fn()')
Set breakpoint on line n of script.js setBreakpoint('script.js', 22) alias : sb(args)
debug> sb(7);
1 function floop (i) {
2 if (i > 0) {
3 var decrementer = 10;
4 while( decrementer-- > 0 ){
> 5 i--;
6 }
* 7 floop(i);
8 }
9 return i;
10 }
debug> c
break in app.js:7
5 i--;
6 }
> 7 floop(i);
8 }
9 return i;
clearBreakpoint('app.js',7) alias : cb(args)
debug> c
break in app.js:7
5 i--;
6 }
> 7 debugger;
8 floop(i);
9 }
node debug app.js
c
c
c
bt
backtrace
alias bt
#0 app.js:7:5
#1 app.js:8:5
#2 app.js:8:5
#3 app.js:13:1
kill with
killall node
process.exit();
debug> c
program terminated
run to start the terminated process
debug> run
< Debugger listening on port 5858
connecting to port 5858... ok
restart will restart the process
debug> restart
program terminated
< Debugger listening on port 5858
connecting to port 5858... ok
$ node --inspect index.js
Run it with the --inspect flag
$ node --inspect --debug-brk index.js
You can also break on the first statement of the script with --debug-brk.
Open the provided URL
By Joe Karlsson
In terminal and node inspector