Debugger in Node.js: Command-Line Debugging Utility

Node.js includes a simple command-line debugger that allows stepping through code, inspecting variables, setting breakpoints, and evaluating expressions. While it is not a full-featured debugger, it provides essential functionality for quick debugging. For advanced usage, Node.js integrates with the V8 Inspector, enabling Chrome DevTools for profiling and step-by-step debugging.

node inspectBreakpointsWatchersreplV8 Inspector

~2 min read • Updated Dec 27, 2025

1. Starting the Debugger


Run Node.js with the inspect argument to start debugging:


$ node inspect myscript.js

By default, the debugger breaks on the first executable line.


2. Resume Until First Breakpoint


To run until the first debugger statement, set the environment variable:


$ NODE_INSPECT_RESUME_ON_START=1 node inspect myscript.js

3. REPL and Expression Evaluation


The repl command allows evaluating code in the current context:


debug> repl
> x
5
> 2 + 2
4

4. Watchers


Watchers track variable values at breakpoints:


  • watch('expr'): Add an expression to the watch list.
  • unwatch('expr'): Remove a watcher.
  • watchers: List all active watchers.

5. Core Debugger Commands


  • cont: Continue execution.
  • next: Step to the next line.
  • step: Step into a function.
  • out: Step out of a function.
  • pause: Pause execution.

6. Breakpoints


  • setBreakpoint(line): Set a breakpoint on a specific line.
  • setBreakpoint('script.js', 1): Set a breakpoint in another file.
  • setBreakpoint('script.js', 1, 'num < 4'): Conditional breakpoint.
  • clearBreakpoint('script.js', 1): Clear a breakpoint.

7. Information and Profiling


  • backtrace: Print the current execution stack.
  • list(5): Show 5 lines of context around the current line.
  • profile / profileEnd: Start and stop CPU profiling.
  • takeHeapSnapshot(): Save a heap snapshot.

8. Execution Control


  • run: Run the script.
  • restart: Restart the script.
  • kill: Terminate the script.

9. V8 Inspector Integration


For advanced debugging, Node.js integrates with Chrome DevTools via the V8 Inspector:


  • --inspect: Start the app and allow debugger attachment.
  • --inspect-wait: Wait for debugger before execution.
  • --inspect-brk: Break on the first line immediately.

$ node --inspect index.js
Debugger listening on ws://127.0.0.1:9229/...

Conclusion


The Node.js Debugger provides essential tools for stepping through code, inspecting variables, and setting breakpoints. Combined with V8 Inspector and Chrome DevTools, developers gain powerful capabilities for profiling, memory analysis, and step-by-step debugging, ensuring more reliable and maintainable applications.


Written & researched by Dr. Shahin Siami