Tutorial on using the debugger in Node.js
Let’s take the node.js application that we wrote in this tutorial and introduce a bug (typo) in the app.js file ….
When you run “node app.js” you get this error on the browser and console…
Using NodeJS Built in Debugger
You can use the built-in nodejs debugger by running …
node debug app.js
And you will get the nodejs debugger prompt at the console…
Here are the common commands that you can type in the debug prompt …
cont – continue
next – run next statement
step – step into the next statement
out – step out of the current function
backtrace – show callstack
watch(expression) – add expression to watch list
list(n) – list the n lines of code around current line.
setBreakpoint(n) – setbreakpoint at line n
Here we show example, where we run next line, set breakpoint at line 5 and “cont” to that breakpoint…
Next we start REPL, examine “app” and determined that it was a function, and view the value of “__dirname”…
Ctrl-C to exit REPL.
Ctrl-C twice to exit debugger.