Skip to Content
Technical Articles

How to debug a Node.JS REST API in Visual Studio Code locally

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.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.