Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
jason_xia
Employee
Employee
VS Code has built-in debugging support for the Node.js runtime and can debug JavaScript, TypeScript, or any other language that gets transpiled to JavaScript.

This article describes the steps about how to debug a REST API developed in Node.JS in Visual Studio Code in local computer.

1.Create a launch configuration file


In order to configure and save debugging setup details, you need to create a launch configuration file. VS Code keeps debugging configuration information in a launch.json file.

Open your project folder in VS Code (File > Open Folder). Click Debug icon on the left side bar. Select the Configure gear icon on the Debug view top bar.



VS Code will try to automatically detect your debug environment. Click Add Configuration button.



Choose "Node.JS: Attach to Process".



Save the file.


2.Attach debugger to Node.JS process


Choose the newly created launch configuration from the droplist of DEBUG button.



Use "npm run start" start your API server. Set breakpoints in source code. Click Start Debugging.



The Debugger shows the list of detected Node.JS processes in your computer. Choose the one for your API.



As soon as a debugging session starts, the DEBUG CONSOLE panel is displayed and shows debugging output, and the Status Bar changes color (orange for default color themes).


Verify debugger


Use Postman app or other tools to send a HTTP request to your API.



The debugger will be set focus automatically once the breakpoint is reached.

Labels in this area