The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
execPath
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.
For example, assuming the following script for process-args.js:
A boolean, string or array of strings to always treat as booleans. If
true will treat all double hyphenated arguments without equal signs as
boolean (e.g. affects --foo, not -f or --foo=bar).
All boolean arguments will be set to false by default.
A string or array of strings argument names to always treat as arrays.
Array options can be used multiple times. All values will be
collected into one array. If a non-array option is used multiple
times, the last value is used.
All Collectable arguments will be set to [] by default.
array: ["input"],
});
The first parameter is the raw CLI parameters list (in most case, it will be process.argv)
The second parameter is the (optional) configuration to parse raw CLI parameters
The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
execPath
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.
For example, assuming the following script for process-args.js:
The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
execPath
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.
For example, assuming the following script for process-args.js:
The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
execPath
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.
For example, assuming the following script for process-args.js:
A boolean, string or array of strings to always treat as booleans. If
true will treat all double hyphenated arguments without equal signs as
boolean (e.g. affects --foo, not -f or --foo=bar).
All boolean arguments will be set to false by default.
boolean: ['get'],
});
the variable args will be equals to (assuming CLI parameters are my-command --get http://my-url.com):
The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
execPath
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.
For example, assuming the following script for process-args.js:
The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
execPath
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.
For example, assuming the following script for process-args.js:
A string or array of strings argument names to always treat as arrays.
Array options can be used multiple times. All values will be
collected into one array. If a non-array option is used multiple
times, the last value is used.
All Collectable arguments will be set to [] by default.
array: ['tag'],
});
the variable args will be equals to (assuming CLI parameters are my-command --tag app:v1 --tag app:latest):
The process.argv property returns an array containing the command-line
arguments passed when the Node.js process was launched. The first element will
be
execPath
. See process.argv0 if access to the original value
of argv[0] is needed. The second element will be the path to the JavaScript
file being executed. The remaining elements will be any additional command-line
arguments.
For example, assuming the following script for process-args.js:
import { argv } from'node:process';
// print process.argv
argv.forEach((val, index)=> {
console.log(`${index}: ${val}`);
});
Launching the Node.js process as:
Terminal window
nodeprocess-args.jsonetwo=threefour
Would generate the output:
0: /usr/local/bin/node
1: /Users/mjr/work/node/process-args.js
2: one
3: two=three
4: four
@since ― v0.1.27
argv);
the variable args will be equals to (assuming CLI parameters are my-command --no-color):