JavaScript Node.js Basics Create a Command Line Weather Application Retrieving Data - Solution

cant get around accessing the api data

const http = require('http');
const api = require('./api.json');
http.get(`api.openweathermap.org/data/2.5/forecast?id=524901&APPID=asasadjahdjh2dh2h272dh27dh27dh27d2hx`,(response)=>{
                  response.on('data',(data)=>{
                  console.log(response.statusCode);
                  });
         });

I need help on this challenge and i have various questions.. for starters... i tried simply using api key and try logging out the data and it did not worked. before that i was trying to get the api key working in an different .json file so other people cant see my key.(i have edited and put in a dummy api key). how can i access the data. im trying to get the api from https://openweathermap.org/api

2 Answers

Steven Parker
Steven Parker
172,267 Points

:bell: Hi, I was alerted by your tag.

This little code snippet is not enough to replicate the issue even if I had a valid API key. However, I have two suggestions:

  1. Look over other questions asked about this same video in the forum. You might find an answer in one of them that relates to your issue.
  2. Make a snapshot of your workspace and post the link to it here. Then someone else who does have a valid API key (perhaps they've recently taken the course) can test your program.

gimme a sec ill post my snapshot with edited code

Steven Parker
Steven Parker
172,267 Points

I took a quick glance and noticed this on line 5 of "weather.js":

const weatherApi = (`https://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${api.key})`;

There's an open parenthesis in front of the string, and a closing one at the end inside the string., and I'd bet neither one should be there.

If that doesn't fix the problem I'd recommend that you take a look at those other forum questions while you wait for someone with an API key to answer.

Steven can i make application like this in the technologies covered in next courses like rest api? Although i understand how to work with the api but just cant seem to get the api link working..

My point was should i move on?

Steven Parker
Steven Parker
172,267 Points

Moving on is always an option, but I think getting it working would provide a great additional learning experience if you feel motivated to do it.

Ali Nawab
Ali Nawab
13,869 Points

The first issue is the parantheses as mentioned by Steven, you also forgot to export the get method (module.export.get) in weather.js which you are using in app.js