JavaScript Node.js Basics Create a Command Line Weather Application Retrieving Data - Solution

Duy Khanh
PRO
Duy Khanh
Pro Student 4,911 Points

Why we need process.argv.slice(2) ?

Anyone can explain about process.argv.slice(2)? Why we need to slice and why the param is 2 ?

1 Answer

Steven Parker
Steven Parker
171,345 Points

The "argv" array contains everything given on the command line. The first item (argv[0]) will be the path to node itself, and the second item (argv[1]) will be the path to your script code.

So a slice starting at 2 will discard both of those and return everything else that was typed on the command line. These are the arguments that will be used to construct the API query string.

Duy Khanh
Duy Khanh
Pro Student 4,911 Points

yeah thanks so lot for answer :D