The Node.js built-in debugger helps you find and fix problems in your code by letting you pause and check what is happening step-by-step.
Node.js built-in debugger in Node.js
node inspect your_script.js
Run this command in your terminal to start the debugger for your script.
You can also start debugging by adding --inspect or --inspect-brk flags for advanced debugging with Chrome DevTools.
app.js file in the terminal.node inspect app.js
node --inspect-brk app.js
cont resumes running the program after a pause.debug> cont (debugger continues running the program)
next runs the next line and pauses again.debug> next (debugger runs the next line of code)
This simple program adds two numbers. The debugger; line pauses the program when running with the debugger, letting you inspect variables.
function add(a, b) {
debugger;
return a + b;
}
console.log(add(2, 3));Use the debugger; statement in your code to set breakpoints easily.
In the debugger prompt, commands like cont, next, step, and repl help you control the program.
You can inspect variables by typing their names in the debugger prompt.
The Node.js built-in debugger helps pause and inspect your code to find bugs.
Start it with node inspect your_script.js or use debugger; in your code.
Use commands like cont and next to control the program flow while debugging.