Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visual Studio Code, how to pass arguments in launch.json

In Visual Studio Code, in the launch.json file that launches the app I'm writing, how do I add command line arguments?

like image 528
Jonathan Benn Avatar asked Sep 11 '19 12:09

Jonathan Benn


People also ask

How do I launch VS Code json?

To create a launch.json file, click the create a launch.json file link in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .vscode folder and added the launch.json file to your workspace.

What is args in launch json?

args. JSON array of command-line arguments to pass to the program when it is launched. Example ["arg1", "arg2"] . If you are escaping characters, you will need to double escape them. For example, ["{\\\"arg1\\\": true}"] will send {"arg1": true} to your application.

Where is launch json Visual Studio Code?

The launch. json file is located in a . vscode folder in your workspace (project root folder).

How do I run a json file in Terminal Visual Studio Code?

In Visual Studio Code, use shortcut Ctrl + Shift + P to open the Command Palette and type Open launch. json . And it will open the launch. json file for you.


2 Answers

As described in the documentation, you need to use the args attribute. E.g.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Debug App",
            "program": "${workspaceFolder}/main.js",
            "args": ["arg1", "arg2", "arg3"]
        }
    ]
}
like image 175
Jonathan Benn Avatar answered Oct 11 '22 12:10

Jonathan Benn


I pass arguments by this way for the python program, it may work for nodejs:

{
    "type": "node",
    "request": "launch",
    "name": "Debug App",
    "program": "${workspaceFolder}/main.js",
    "args": ["--arg1", "value1", "--arg2", "value2"]
}
like image 10
Navid Shad Avatar answered Oct 11 '22 13:10

Navid Shad