Debugging is the process of identifying a problem or a bug and 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 guide will show you how to debug Node.js code in VS Code quickly:
- 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 the file you want to debug in Visual Studio Code. - Select the Run and Debug button from the “Run” tab in the sidebar, or press F5. Visual Studio Code will try to run your currently active file.
From the Run tab, select the Run and Debug button. - 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.
This is the debug environment. The debugging output will be displayed in the debug console. - Debugging will begin. The debugging output will be displayed in the Debug Console panel at the bottom of the code editor.
That’s it! We’ve 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.