Skip to content

Commit c7b74fb

Browse files
committed
Added process.argv
1 parent 5fb92fd commit c7b74fb

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎chapters/globals.md‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,20 @@ An object containing the user's environment variables, for example:
9393
, _: '/usr/local/bin/node'
9494
, OLDPWD: '/Users/tj'
9595
}
96-
96+
97+
### process.argv
98+
99+
When executing a file with the `node` executable `process.argv` provides access to the argument vector, the first value being the node executable, second being the filename, and remaining values being the arguments passed.
100+
101+
For example our source file _./src/process/misc.js_ can be executed by running:
102+
103+
$ node src/process/misc.js foo bar baz
104+
105+
in which we call `console.dir(process.argv)`, outputting the following:
106+
107+
[ 'node'
108+
, '/Users/tj/EBooks/masteringnode/src/process/misc.js'
109+
, 'foo'
110+
, 'bar'
111+
, 'baz'
112+
]

‎src/process/misc.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ console.log('getuid():   ' + process.getuid());
99
console.log('getgid():   ' + process.getgid());
1010
console.log('ENV:');
1111
console.dir(process.env);
12+
console.dir(process.argv)

0 commit comments

Comments
 (0)