How To Debug Node.js Code In Visual Studio Code

Debugging is the process of identifying a problem or a bug and either correcting it or figuring out how to work around it. Visual Studio Code has built-in debugging support for JavaScript, TypeScript, and Node.js. Therefore, you do not require any extensions to debug these codes. This post will discuss how to debug a Node.js code in Visual Studio Code.

Download and Install Node.js

Download and install Node.js from nodejs.org with default configurations.

How To Debug Node.js Code In Visual Studio Code?

Follow these steps to debug on VS Code:

  1. Open the file you want to debug. In our case, we are debugging a JavaScript program. So, I will select the index.js file.

    Open JavaScript File
    Open the file you want to debug in Visual Studio Code.
  2. Select the Run and Debug button from the”“Ru”” icon in the sidebar or press F5. Visual Studio Code will try to run your currently active file.

    Open Run and Debug
    From the Run view, select the Run and Debug button.
  3. Visual Studio Code will try to detect your debug environment automatically. Our debugger is now attached, and Visual Studio Code has automatically found your program.

    Debug Environment
    This is the debug environment, and the debug result will be outputted in the debug console.
  4. Debugging will begin, and you will have the Debug Console panel at the bottom of the code editor, which shows debugging output.

There it is!We’vee just debugged a simple Node.js code in Visual Studio Code. You can play around with the debugging environment using the breakpoints and the debug toolbar. Follow our debugging walkthrough to learn more about using breakpoints and the debug toolbar.

Was this article helpful?

Leave a Comment