How to Debug node.js application in VScode?

To debug a Node.js application using Visual Studio Code, follow these steps: 

 1. Install the Visual Studio Code editor from the official website: https://code.visualstudio.com/ 

 2. Open your Node.js project in Visual Studio Code.

 3. Make sure you have a `launch.json` configuration file in your project. If you don't have one, you can create it by clicking on the "Run and Debug" icon in the sidebar and selecting the "Add Configuration" button. Choose the "Node.js" environment. 4. In the `launch.json` file, you'll see a default configuration for debugging Node.js. By default, it launches the currently open JavaScript file. You can customize this configuration as needed, such as specifying the entry point file or adding environment variables. 

 5. Place breakpoints in your code by clicking in the left margin of the editor or using the shortcut `F9`. Breakpoints are markers that pause the execution of your code at specific lines, allowing you to inspect variables and step through the code. 

 6. Start the debugging session by selecting the debug configuration you want to use from the drop-down menu in the top toolbar. It should be the name you provided in the `launch.json` file. Alternatively, you can press `F5` to start debugging. 

 7. Once the debugging session starts, your Node.js application will run, and it will stop at the breakpoints you set. You can use the debug toolbar at the top to control the execution flow, step through the code, examine variables, and view call stacks. 

 8. While debugging, you can use the various debug-related buttons in the toolbar, such as stepping in (`F11`), stepping over (`F10`), stepping out (`Shift + F11`), and stopping the debugging session (`Shift + F5`). 

 9. You can also open the Debug Console in Visual Studio Code by selecting the "Debug Console" tab in the bottom panel. It allows you to execute JavaScript code and view console output during debugging.

 10. Finally, once you have finished debugging, you can stop the debugging session by clicking on the red "Stop" button in the debug toolbar or by pressing `Shift + F5`. By following these steps, you can effectively debug your Node.js application using Visual Studio Code.

Comments