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 trialSaud Tauqeer
Courses Plus Student 8,099 Pointscant 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
231,236 PointsHi, 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:
- 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.
- 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.
Saud Tauqeer
Courses Plus Student 8,099 Pointsgimme a sec ill post my snapshot with edited code
Saud Tauqeer
Courses Plus Student 8,099 Pointshttps://w.trhou.se/ioca74gkz8 here you go
Steven Parker
231,236 PointsI 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.
Saud Tauqeer
Courses Plus Student 8,099 PointsSteven 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..
Saud Tauqeer
Courses Plus Student 8,099 PointsMy point was should i move on?
Steven Parker
231,236 PointsMoving 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
13,869 PointsThe 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
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 PointsSteven Parker