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: http://api.wunderground.com/api/${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 = `https://api.wunderground.com/api/${api.key}/conditions/q/${state}/${city}.json`

and giving the function the two arguments:

weather.get(state,city);

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

Nico Trivelli
Nico Trivelli
20,352 Points

Great answer!

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

1 Answer

Michael Braga
Michael Braga
Full Stack JavaScript Techdegree Student 18,992 Points

With destructuring assignment, you can also do this:

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

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