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 2017 Create a Command Line Weather Application Project Overview

Server connect error with Node weather app API call. Any ideas?

Hey everyone! I'm having an issue with an invalid API key from openweathermap.org and I have no clue why that's the case.

Here is my code so far. I'm just wanting to print out the data. The error message I'm getting from node is at the bottom. of the page.

Maybe this is because I've made an API request from them in the last 10 minutes and now they're giving me the boot for a while? Any ideas, guys? Thank you!


//Sign up for API //API key: ?

const https = require('https');

//Retrieve the data from API URL using zip code function getWeather(zipCode, countryCode = 'us'){ //RegEx to validate error for input //if RegEx passes, zip is valid, else print error message const APIKey = '?'; const request = https.get(https://api.openweathermap.org/data/2.5/weather?zip=${zipCode},${countryCode}&appid=${APIKey}.json, (res) => { let body = '';

res.on('data', data => {

  body += data.toString();

});

res.on('end', () => {

  //Parse the data, since it's in JSON
  //Print out the information we have obtained with the API

  const weatherData = JSON.parse(body);
  console.log(weatherData);

// const farenheight = (weatherData.main.temp * (9/5) - 459.67); // console.log(farenheight); // printWeather(Current temperature in ${weatherData.name} is ${farenheight} \xBA F.);

});  

});

}

getWeather(28202);

Console print out: events.js:160
throw er; // Unhandled 'error' event
^

Error: connect ECONNREFUSED 162.243.53.59:443
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)

2 Answers

David Mendiola
seal-mask
.a{fill-rule:evenodd;}techdegree
David Mendiola
Full Stack JavaScript Techdegree Student 16,579 Points

Hi Reid,

If you are using open weather map api I had success with http instead of https also an error in their code the argument for

APPID should be lowercase appid after changing that it worked for me as I was getting similar errors.

Hey David, thank you so much. All great points!

Kevin Korte
Kevin Korte
28,149 Points

What code is on line 160 of events.js?

Also, make sure you at some point, destroy that API key on your account and issue a new one. Now that it's posted online, you wont want to leave that key associated with your account. Spiders and bots crawl the web looking to farm api keys for anything.

I'm not sure where to find that information within my Workspace. I've edited the API key. Thank you!

Kevin Korte
Kevin Korte
28,149 Points

Is events.js one of your files?