launch json

What is Launch JSON?

Launch JSON is a configuration file used by Visual Studio Code for launching and debugging applications. It contains various settings such as the type of application to be launched, arguments to be passed, environment variables, and more.

How to create a Launch JSON file?

To create a Launch JSON file in Visual Studio Code, follow these steps:

  1. Open your project in Visual Studio Code.
  2. Press F5 or click on the Debug icon in the sidebar.
  3. Click on the gear icon next to 'No Configurations' and select 'Add Configuration'.
  4. Select the type of application you want to launch (e.g. Node.js, Python, etc.)
  5. A default Launch JSON file will be created with some basic settings.

Understanding the Launch JSON file structure

The default structure of a Launch JSON file looks like this:


{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "type",
      "request": "request",
      "name": "name",
      "program": "program",
      "args": [],
      "cwd": "cwd",
      "env": {},
      "console": "console",
      "stopOnEntry": false,
      "outFiles": []
    }
  ]
}

The important fields in this file are:

  • type: The type of application to be launched (e.g. Node.js, Python, etc.)
  • request: The type of request to be made (e.g. launch, attach, etc.)
  • name: A name for the configuration
  • program: The entry point for the application (e.g. app.js)
  • args: An array of arguments to be passed to the application
  • cwd: The current working directory for the application
  • env: An object containing environment variables to be set
  • console: The type of console to be used (internalConsole, integratedTerminal, externalTerminal)
  • stopOnEntry: Whether to stop on the first line of the application
  • outFiles: An array of output files generated by the application

Customizing the Launch JSON file

You can customize the Launch JSON file according to your needs. For example, if you want to debug a Node.js application with nodemon, you can use the following configuration:


{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "nodemon",
      "runtimeExecutable": "nodemon",
      "program": "${workspaceFolder}/index.js",
      "restart": true,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "protocol": "inspector"
    }
  ]
}

In this configuration, we have used nodemon as the runtime executable, specified the entry point as index.js, enabled restart on file changes, and used the integrated terminal for the console.

You can also add multiple configurations in the Launch JSON file and switch between them as needed.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe