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 (2014) Building a Command Line Application Making a GET Request with http

Andrey Ryazanov
Andrey Ryazanov
7,886 Points

making a get request. node.js challenge

Cannot pass through Task 2 of making a get request node.js challenge. Pls help.

Task: "On a new line, call the get method on the http object you created. Pass in the string of http://teamtreehouse.com/chalkers.json."

My code:

app.js
var http = require("http");
http.get("http://teamtreehouse.com/" + "chalkers" + ".json");
Andrey Ryazanov
Andrey Ryazanov
7,886 Points

Wow. I passed it. The weird solution:

var http = require("http");
var https = require("https");
http.get("http://teamtreehouse.com/chalkers.json")
https.get("https://teamtreehouse.com/chalkers.json")

6 Answers

Antonio De Rose
Antonio De Rose
20,882 Points

this did work for me eventually.

const https = require('https');

https.get("https://teamtreehouse.com/chalkers.json", response => { });

Ryan Zimmerman
Ryan Zimmerman
3,854 Points

Yeah I haven't done this one yet. But when you make a get request depending on if it is http or https can really affect the api you are trying to grab. A lot of times you will return a header and have to build an if statement to see which one you get and go from there.

Seth Kroger
Seth Kroger
56,407 Points

I think the challenge is looking for you to pass in the whole string, since that is what it's asking for. Using concatenation shouldn't matter because you'll end up with the same string, but with the checking software it does. I've checked and just this works, but breaking up the URL doesn't.

http = require('http');

http.get("http://teamtreehouse.com/chalkers.json");
Eric Green
Eric Green
6,521 Points

The https passed for me. I agree with Ryan. The when you make a get request depending on if it is http or https can really affect the api you are trying to grab!

https.get('https://teamtreehouse.com/chalkers.json');

The teacher is really bad and the challenge isn't properly adjusted. You need to add steps 2 and 3 together in order to pass step 2, and then just press check work again and you pass step 3.