65

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

Jonathan Benn
  • 2,908
  • 4
  • 24
  • 28

2 Answers2

81

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"]
        }
    ]
}
Krishna
  • 6,107
  • 2
  • 40
  • 43
Jonathan Benn
  • 2,908
  • 4
  • 24
  • 28
  • 1
    @eigenfield have you tried filing a bug report with Visual Studio Code or Kotlin? – Jonathan Benn Jan 25 '21 at 01:11
  • 10
    just to clarify args array, `"args": ["key=value", "key=value"]` – Muhammad Awais Jul 01 '21 at 17:15
  • @AwaisNasir is that suggestion for Kotlin? Or in general? In practice, I've used simple strings and not key-value pairs. – Jonathan Benn Jul 02 '21 at 12:35
  • 1
    @JonathanBenn I don't know about kotlin, thats the general solution, for me key value pair solution worked and not simple strings – Muhammad Awais Jul 02 '21 at 12:43
  • Alright, it seems that Your Mileage May Vary. For Node.JS, I've used a simple string (not a key-value pair) without any trouble. In any case, the input is always a string regardless what's _in_ the string. – Jonathan Benn Jul 02 '21 at 13:00
  • When passing `args` to `launch.json`, the args are added to the call: `node ./test/test.js --no-warnings`. However, I need the args right after `node`:`node --no-warnings ./test/test.js`. Solution in launch.json: `"args": ["--no-warnings","${file}"]` – Timo Aug 20 '22 at 06:54
  • Hi @Timo, the placeholder `${file}` seems to get replaced by the `launch.json` file path. Is that what happens for you? – Jonathan Benn Aug 29 '22 at 19:27
  • 1
    If I run this as is, I get an error: `launch: property 'cwd' is missing or empty`. I had to manually add this line to the launch.json to get it to work ``` "cwd": "${workspaceFolder}" ``` – Raleigh L. Sep 07 '22 at 03:36
26

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"]
}
Navid Shad
  • 738
  • 7
  • 15