Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Duy Khanh
PLUS
Duy Khanh
Courses Plus 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
231,269 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.

HI STEVEN please can you explain how to construct the api query string

Steven Parker
Steven Parker
231,269 Points

That part is covered in the video. And for this particular API, it's just a URL.