Skip to content

Latest commit

 

History

History
21 lines (18 loc) · 544 Bytes

section13.2.md

File metadata and controls

21 lines (18 loc) · 544 Bytes

Section 13.2: process.argv command line arguments

process.argv is an array containing the command line arguments. The first element will be node , the second element will be the name of the JavaScript file. The next elements will be any additional command line arguments.

Code Example:

Output sum of all command line arguments index.js

let sum = 0;
for (i = 2; i < process.argv.length; i++) {
  sum += Number(process.argv[i]);
}
console.log(sum);

Usage Exaple:

node index.js 2 5 6 7

Output will be 20