To pass command-line arguments to a Node.js program when you debug it on a Mac, add an args array to its VS Code launch configuration. Put each argument in its own string, then start that configuration with F5. This passes values directly to the program; it does not make zsh interpret the array as a shell command.
Add an args array to launch.json
Open the project folder in VS Code. If it does not already have a launch configuration, open Run and Debug with ⇧⌘D, choose create a launch.json file, and select the debugger for your runtime. VS Code saves a workspace configuration in .vscode/launch.json. A launch request starts a new process; an attach request connects to one already running, so use launch when VS Code should start the program with your arguments. Configure debugging in Visual Studio Code
For this concrete example, assume the workspace contains app.js, and you want to run it with --input followed by a file path that may include spaces, plus a --verbose flag. Add or adapt this configuration inside the configurations array:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug app with input file",
"program": "${workspaceFolder}/app.js",
"cwd": "${workspaceFolder}",
"args": [
"--input",
"${workspaceFolder}/data files/input.txt",
"--verbose"
]
}
]
}
Choose Debug app with input file in the Run and Debug configuration selector, then press F5. program identifies the JavaScript entry point, cwd sets the working directory, and args supplies the additional command-line values. The debugger extension defines supported properties for each runtime; check IntelliSense in launch.json if you are using a different debugger or see a validation error. Configure debugging in Visual Studio Code
Keep spaces and special characters intact
In array-valued args, each element is one argument. VS Code documents that a path containing spaces remains a single string after variable substitution. Therefore, the example’s file path is one argument; do not add embedded escaped quotation marks around it just to preserve the space. ${workspaceFolder} resolves to the folder opened in VS Code, which keeps the path tied to the project. Variables reference
This is different from typing a command into Terminal. macOS uses zsh as Terminal’s default shell, but the launch configuration’s args array represents arguments to the target process. Shell syntax such as *, >, or | is not automatically expanded or executed there. For example, if your program expects the literal value a&b.txt, write it as one JSON string: "a&b.txt". For shell expansion or redirection, the target must explicitly be run through a shell, and the exact behavior depends on the debugger extension; VS Code notes that there is no universal redirection syntax for all debug configurations. Apple: Change the default shell in Terminal on Mac and Configure debugging in Visual Studio Code
Confirm what the program receives
For Node.js, the process exposes launch arguments through process.argv. The first entries represent the Node executable and script path; the remaining entries are the extra values. To inspect them temporarily, add this to app.js:
console.log(process.argv);
With the example configuration, the output should include --input, the resolved path ending in data files/input.txt, and --verbose as separate entries. This is a practical way to tell whether a problem is in VS Code’s configuration or in the program’s argument parsing. Remove or adapt the diagnostic output once you have confirmed the values. Node.js: Process
Ask for a value each time you debug
If the value changes between runs, VS Code supports promptString input variables in launch.json. Add an inputs array at the same top level as configurations, then refer to that input inside args:
"args": ["--input", "${input:inputFile}"],
"inputs": [
{
"id": "inputFile",
"type": "promptString",
"description": "Path to the input file",
"default": "data files/input.txt"
}
]
The prompt returns a string, which is substituted into the argument element. This is useful for a simple per-run value. Input-variable nesting is unsupported, and the input prompt does not parse a shell command line into multiple arguments. If you need several values, define several array elements or use a more suitable debugger-specific approach. Variables reference
Troubleshoot arguments that seem missing
First confirm the right configuration is selected and that the request is launch. Then check that the argument list is in the debugger’s supported args property, that its commas and quotation marks form valid JSON, and that your program expects those values in the order supplied. Also verify cwd: a relative path is interpreted by the program in relation to its working directory, while ${workspaceFolder} provides a project-root starting point. VS Code recommends checking program, cwd, args, and the selected debugger’s supported properties when a launch does not behave as expected. Configure debugging in Visual Studio Code
For a repeatable Mac debug run, store the arguments in the workspace’s launch configuration, use one JSON array element per intended value, and inspect what your runtime actually receives. Treat shell quoting as a separate concern: it applies when a shell parses a command, while args is configuration for the launched program.
Sources
Configure debugging in Visual Studio Code — Microsoft
Variables reference — Microsoft
Process — Node.js