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 (2014) Building a Command Line Application Perfecting: Getting Multiple Profiles

Best solution for command line weather app using forecast.io

So I don't see any thread where there's a way for people who're stuck at the Extra Credit weather app to figure out what to do.

Most people have used other APIs instead of forecast because the other ones take zip codes directly and are hence easier. Because forecast.io needs latitude and longitude. So for forecast, we need another API first to convert zip code to latitude and longitude.

I think as a coding challenge, it's not right for us to use 'easier' APIs like OpenWeather etc as they accept Zip Codes or city names directly. They have one step less, but that means we don't get to practice using two APIs in the same app and feeding the results of one API to the other.

Hence, I have chosen to use zipcodeapi.com to convert zip codes to lat and long coordinates.

It's very simple code, all you need to do is add you API key from zipcodeapi.com in getLocation.js and from https://developer.forecast.io in getWeather.js

The only confusing part of the code is going to be "callback" that I have used throughout to be able to share data objects between files, so if at all anyone needs help explaining that, reply to this thread.

Feel free to fork the workspace and try it out on your own!

2 Answers

Here is my take on the app:

http://w.trhou.se/52yttnrtda

Please remember to add your API keys before using a command like

node app.js 90210

Without the API keys you'll get a not found error, obviously.

Bhavesh Bansal
Bhavesh Bansal
13,810 Points

Here is my take http://w.trhou.se/2yien43770

You can pass City Name, Zip Code or Lat/Long (city name) - node app.js London

(zip code) - node app.js 94040

(lat,long) - node app.js 35 129

Any suggestions are welcomed I am using Open Weather Map API. I have included my API Key but if you want you can get your API key from http://openweathermap.org/api

Good solution. But again, I think that the point of this exercise shouldn't be getting the job done using other APIs. As this is a practice project, where we need challenges and complications to learn. Open weather gives weather details taking any of the following parameters: By city name By city ID By geographic coordinates By ZIP code

This completely take the "conversion" process out of the picture. It is a better practice to use forecast.io because Tree house students will learn how to connect to two different APIs and make them talk to each other in the same app.

Bhavesh Bansal
Bhavesh Bansal
13,810 Points

Aviral Kulshreshtha Thank you for your suggestion. Thats true, I was presenting an alternative solution but you are right we are in practice and learning phase and we should take challenges and complications to learn. Ok I will try to implement this with forecast API and will post it here if face any problem. Cheers!