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 trialJake Kobs
9,215 PointsProject error: unable to determine the domain name
I've been searching on https://openweathermap.org/current#current_JSON for a JSON file that has either http or https as a domain, but all I see are api at the beginning of the site name. Is it possible to do:
const api = require("api")
and use that name to call the get method?
3 Answers
minah
6,290 PointsMight save some time if you are like me new in working with the APIs :) You need to require 'https' in your code and not 'api'. Then you call the get method on your https variable and add 'https://' in the beginning of you API URL, so your code will look like this :
const https = require('https');
const city = 'Stockholm';
const apiKey = 'your api key';
function printMessage(city, temp){
console.log(`${city}: ${temp}`);
}
const request = https.get(`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}`,
response => {
console.dir(response);
});
Adam Beer
11,314 PointsCan not use require method. Create a new file for API. Create a new file, and add name to, like this api.json. Inside the app.json add to the parameters. What happens? Hope this help
Antti Lylander
9,686 Pointsopen weather map's api uses http protocol. You need an api-key first.