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 trialErik L
Full Stack JavaScript Techdegree Graduate 19,470 PointsUnable to follow section...
Hello, so I just finished this section, https://teamtreehouse.com/library/handling-errors-solution, but I was unable to follow at all. the teacher uses a different api, I think the videos need to be updated, I was able to copy code from the teacher's notes, but I am having trouble understanding how I am supposed to make it work. What I have done is that I signed up for a API key for https://openweathermap.org/. But I was told my API key won't be available until a few hours this is the code thatI found in the notes
const weather = require('./weather');
const query = process.argv.slice(2).join(' ');
//query: 90201
//query: Los Angeles
weather.get(query);
const https = require('https');
const querystring = require('querystring');
const api = require('./api.json');
// Print out temp details
function printWeather(weather) {
const message = `Current temperature in ${weather.name} is ${weather.main.temp}F`;
console.log(message);
}
// Print out error message
function get(query) {
//const url = `https://api.wunderground.com/api/${api.key}/geolookup/conditions/q/${query}.json`;
const parameters = {
APPID: api.key,
units: 'imperial'
};
const zipCode = parseInt(query);
if (!isNaN(zipCode)) {
parameters.zip = zipCode + ',us';
} else {
parameters.q = query + ',us';
}
const url = `https://api.openweathermap.org/data/2.5/weather?${querystring.stringify(parameters)}`;
console.log(url);
const request = https.get(url, response => {
let body = '';
// Read the data
response.on('data', chunk => {
body += chunk;
});
response.on('end', () => {
//Parse data
const weather = JSON.parse(body);
//Print the data
printWeather(weather);
});
});
}
module.exports.get = get;
//TODO: Handle any errors
Can someone please break down on how to make this app work in the console?? where I should put my API key? Thanks so much