❮ Array
❯
- process
- argv
Command line arguments (argv)
Throught the process object we can access the command line of our program. The first value is node itself. The second value is our code, then come the values from that the user supplied.
examples/basic/argv.js
console.log(process.argv.length); console.log(process.argv); console.log('') console.log(process.argv[0]); console.log(process.argv[1]); console.log(process.argv[2]); console.log(process.argv[3]); console.log(process.argv[4]);
$ node argv.js "hello world" Foo
4 [ '/opt/node-v12.14.1-linux-x64/bin/node', '/home/gabor/work/slides/nodejs/examples/basic/argv.js', 'hello world', 'Foo' ] /opt/node-v12.14.1-linux-x64/bin/node /home/gabor/work/slides/nodejs/examples/basic/argv.js hello world Foo undefined