- Open launch.json in Visual Studio Code
- Launch.json structure overview
- Configuring startup settings for different languages
- Debug Configuration Recipes
- Attach the debugger to a running process
- Remote application debugging
- Debugging unit tests and test suites
- Pass environment variables
- Advanced debugging
- Conditional breakpoints and registration points
- Source maps
- Integration of external debuggers
- Debugging multithreaded applications
- Debugging multiple targets
- Troubleshooting common launch.json problems
- Tips for launching.json
- Start debugging
Effective debugging and code quality are inseparable concepts in software development. Visual Studio (VS) Code debugging functionality is primarily controlled by the launch.json file. This file allows developers to configure and manage their debugging configurations as they see fit.
This article will guide you through opening and managing the launch.json file for optimal debugging.
Open launch.json in Visual Studio Code
To configure and manage VS Code debugging settings, you will need access to the launch.json file. This file plays a crucial role in customizing debugging.
- Open the Visual Studio code.

- Press Ctrl + Shift + P to open the command palette.

- Type “Open launch.json” in the command palette and press “Enter.” This should open the launch.json file.

- If the launch.json file does not open, check that the “.vscode” folder exists in the root folder of your project.
- If it does not exist, create a new folder called “.vscode” inside your User folder.

- Create a new file “launch.json” and place it in this folder.

The launch.json file will be ready to configure after you enable it.
Launch.json structure overview
Launch.json displays the “version” and “configs” sections. The “settings” section is an array containing different debugging options, which you will use to configure your debugging scheme.
Each object in the “configs” array represents a debugging scenario. These objects have properties that define the debugging environment, such as language, program, and debugger settings.
Some common properties you’ll find in launch.json configurations include:
- “name” – An easy-to-read name for the setting to identify it in the drop-down menu.
- “type” – Specifies the type of debugger (such as “node”, “python”, or “cppvsdbg”).
- “request”: Determines the type of request, either “start” (to start a new instance) or “attach” (to attach the debugger to an existing process).
- “program”: path of the file you want to debug.
- “args” – A series of command line arguments to pass to the program during debugging.
- “preLaunchTask”: A task to be executed before starting the debugger.
Understanding the structure of the launch.json file lets you know which options to change and which to leave alone as you customize your debugging environment.
Configuring startup settings for different languages
The steps to configure startup settings may vary slightly depending on the language. Here are the steps for several popular languages.
JavaScript and typescript
- Create a new launch.json file and set the “type” property to “node” for JavaScript or “pwa-node” for TypeScript.

- Set the “request” property to “start” or “attach”.


- You must specify the entry point file using the “program” property.

Piton
- Install the Python interpreter and the extension for Visual Studio Code.

- Set the “type” property to “python” in a new launch.json file.

- Set the “request” property to “start” or “attach”.

- Specify the Python file to run using the “program” property.

- You may need to additionally set the “pythonPath” property to the Python interpreter path if it is not in the default location.

C# and .NET Core
- Install the C# extension for Visual Studio Code.

- In the new launch.json file, set the “type” property to “coreclr” for .NET Core or “clr” for .NET Framework.

- Set the “request” property to “start” or “attach”.

- Specify the entry point file using the “program” property.

- Set the “cwd” property to the working directory of the current project if necessary.

Java
- Install the Java extension package.

- Create a new launch.json file and set the “type” property to “java”.

- Set the “request” property to “start” or “attach”.

- Specify the main class with the “mainClass” property.

- Set the “projectName” property to the name of your Java project.

- Set the “classpath” property to include the Java libraries that you will use during your Java development.

Debug Configuration Recipes
The next section covers several debugging configuration recipes.
Attach the debugger to a running process
To attach the debugger to a running process:
- Set the “request” property to “attach”.

- Choose the process ID or filter to find the process to debug.

Remote application debugging
For remote application debugging:
- Use a “remote” type.
- Provide the host address, port, and possibly authentication information to establish a connection.
Debugging unit tests and test suites
When debugging unit tests and test suites:
- Use a configuration that includes the testing framework and configuration to debug unit tests and test suites.
- Define the test suite or inpidual test files in the “program” or “args” property to perform specific tests.
Pass environment variables
The “env” property in launch.json can pass environment variables to your application while debugging. This property is an object that contains key-value pairs for the environment variables that you want to set.
Advanced debugging
Let’s explore some advanced debugging techniques for users who want to squeeze a little more power out of debug files.
Conditional breakpoints and registration points
Breakpoints and conditional log points improve debugging by pausing or logging messages only under specific conditions. To use them:
- Right click on the line number where you want to set a breakpoint or registration point.
- Select “Add Conditional Breakpoint” or “Add Registration Point”.
- Enter the condition or message to trigger the action.
Source maps
Source maps allow you to debug code that has been transformed or minified.
- Set the “sourceMap” property to “true” in your launch.json configuration to use source maps.
- Make sure your build process generates source maps and transformed code.
Integration of external debuggers
You can integrate external debuggers and tools, such as gdb or lldb, into VS Code if you want.
- Install the debugger extension of your choice.
- Configure the debugger settings in the launch.json file.
Debugging multithreaded applications
When debugging multithreaded applications, you can control the execution of inpidual threads.
- Use the “threads” view in the debugging sidebar to manage threads during a debugging session.
- You can pause, resume, or step through code execution for each thread separately.
Debugging multiple targets
Composite launch configurations allow debugging of multiple targets simultaneously. If you want to take advantage of this feature, add a “composite” array with configuration names to group together. Run them by choosing the name of the composite configuration from the Debug drop-down menu.
Configure multiple release configurations targeting different services, functions, or endpoints to debug microservices and serverless applications. Use composite launch setups to execute these targets together.
For multi-root workspaces, create separate launch.json files for each folder. Configure startup settings for each root folder inpidually to debug projects separately or simultaneously using composites.
Troubleshooting common launch.json problems
Sometimes debugging is prone to its own set of errors. Let’s look at some common problems and how to fix them.
Schema validation errors
Schema validation errors occur when a launch.json file has invalid properties or values. To fix schema errors:
- Review the error messages in the Problems panel.
- Update the launch.json file based on the information in the error message.
Debugging failures
Incorrect startup configuration can cause debugging errors.
- Check your startup configurations for incorrect file paths.
- Check for missing or incorrect request or debugger types.
- Update settings as necessary.
Diagnosing startup configuration problems
To diagnose problems with startup configurations:
- Enable diagnostic logging by setting the “trace” property to “verbose”.
- Review the logs generated in the debug console to identify and resolve any issues.
Tips for launching.json
Use launch.json optimally with these tips:
- Use meaningful names for your launch configurations so they are easily identifiable. This practice helps you quickly find the right configuration when working with multiple debugging scenarios.
- Share launch configurations with your team by including the launch.json file in your project’s version control system. Each team member can access the same configurations and debugging settings.
- Version control systems like Git can track changes to your launch.json file. You can use version control to revert to previous configurations and collaborate with other team members by sharing recommended configurations with them.
- Install extensions that support specific languages, debuggers, or tools that fit the demands of the project. Configure the launch.json file to use these extensions and their functions during debugging sessions.
Start debugging
By harnessing the power of launch.json, you can fine-tune your debugging experience to best fit your coding style. This will improve the quality and performance of your code.
How often do you have to configure startup settings? Do you have any setup tips? Share your experiences in the comments section below.