LoginSignup
0
0

More than 3 years have passed since last update.

Node.jsのprocess.argv[i]とは

Last updated at Posted at 2019-11-26

Node.jsのファイルで以下のような記述がありました。

index.js
'use strict';
const number = process.argv[2] || 0;
let sum = 0;
for (let i = 1; i <= number; i++) {
  sum = sum + i;
}
console.log(sum);

それに対して、いかのような記述をすると、

console
$ node index.js 3
> 7

となります。
つまり、node index.js 3の3の部分が、process.argv[2]に当てはまるということです。
process.argv[0]だったら、node
process.argv[1]だったら、index.js
を意味します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0