JavaScript Node.js Basics Create a Command Line Weather Application Parsing Data and Printing - Solution

Petar Karagenov
Petar Karagenov
8,608 Points

The readableQuery const

The url Andrew Chalkley uses does not do what is shown on the video. The url given in the documentation looks like this:${key}/conditions/q/CA/San_Francisco.json - it includes a state. So now the get function requires one more property and also gives the part //const query = process.argv.slice(2).join("").replace(' ', '');// a serious issue. I am stuck with that.

Hi Petar , I had the same problem and fixed it by using:

var state = process.argv.slice(2)[0];
var city = process.argv.slice(3);

var queryString = `${api.key}/conditions/q/${state}/${city}.json`

and giving the function the two arguments:


I admit it is not very elegant, maybe someone found a prettier solution ?

Nico Trivelli
Nico Trivelli
20,353 Points

Great answer!

If I could, I'd vote it best answer definitely!

1 Answer

Michael Braga
Michael Braga
Full Stack JavaScript Techdegree Student 20,764 Points

With destructuring assignment, you can also do this:

const [,, state, city] = process.argv;

var queryString = `${api.key}/conditions/q/${state}/${city}.json`;