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 trialbenjaminmosery
6,346 Points"This Key does not exist"
After running the following code in node.js I am getting the error "error": { "type": "keynotfound" ,"description": "this key does not exist".
Here is the main body of my application:
// Problem: We need a simple way to look at the weather in a certain city
// Solution: Use Node.js to connect to Wunderground's Weather API to get weather information to print out
const https = require ("https");
const api = require (`./api.json`);
//Function to print Message to Console
function Printmessage (weather) {
const message = `Current temperature in ${weather.location.city} is ${weather.current.observation.temp_f} F.`;
console.log(message)
}
//Connect to the API URL (https://api.wunderground.com/api.json)
function get (query) {
const GetWeather = https.get (`https://api.wunderground.com/api/${api.key}/geolookup/conditions/q/${query}.json`, response => {
//Read the Data in
let body = ``;
response.on('data', chunk => {
//GETTING THE BODY BY WRITING IN THE WEBSITE RESPONSE
body+= chunk; //HAVING THE DATA APPEAR IN THE CONSOLE
});
response.on(`end`,() => {
console.log(body);
});
//Parse the .json Data (as its in a string)
//Print the Data
});
}
module.exports.get = get;
Why am I getting this error? My api key is valid according to the wunderground site and is stored in a seperate JSON file. Any help would be appreciated.
2 Answers
Carlos Lantigua
5,938 Pointsit my help to take out the http(s).. the intructor video shows that he used the http(s) but it specifically says on the site to only use http. once I did this on mine it got rid of my errors. Also, if this does not work you might need to take steps to get a replacement key or copy paste the key directly from the API site. Hope this helps.
Adam Lyles Kauffman
14,016 Pointsthe api service provided in your code no longer offers free api keys to the public. there is a new service openweathermap.org which will give you a key after registering for an account. use the updated code provided in the teachers notes for both files, also update the key value in your api.json. after parsing the new data from the new weather api service stored in the varible body, you can now access new objects using dot notation. for example my message ended up being const msg = Current tempature in ${weather.sys.name} is ${weather.main.temp} with the max tempature being ${weather.main.temp_max} and the minimum being ${weather.main.temp_min};