Appendix: Debugging

Let's explore how we can debug our Deno programs.

To start debugging with Deno, we need to add the --inspect or --inspect-brk flag to the run command. These flags are the same also with Node.js.

  • --inspect flag allows attaching the debugger at any point in time.
  • --inspect-brk flag will wait for the debugger to attach and pause execution on the first line of code.

The --inspect-brk flag is the best choice if our script is short since it gives us time to pause and continue the code execution otherwise the program would complete before we can work on it.
Deno supports the V8 Inspector Protocol (used by Chrome and Node.js) that offers extensive debugging capabilities. We can use any Chromium Dev Tools (not only Chrome) to debug our scripts or any IDE supporting the protocol, like Visual Code, for instance.

Debugging with VS Code

It’s possible to debug Deno programs using our favorite IDE. This solution, compared to Chrome Dev Tools, allows us to remain in the same context as the code we are implementing. In the “Appendix: Further Resources”, we can find the links to the official IDE extensions for VS Code and JetBrains.

In this lesson, we’ll learn step-by-step how to configure the VS Code and debug a file.

  1. Install the VS Code extension for Deno.

Get hands-on with 1200+ tech skills courses.