Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Node.js Basics 2017 Create a Command Line Weather Application Project Overview

Jake Kobs
Jake Kobs
9,215 Points

Project 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

Might 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
Adam Beer
11,313 Points

Can 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
Antti Lylander
9,674 Points

open weather map's api uses http protocol. You need an api-key first.