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

Jacob Bender
Jacob Bender
15,300 Points

Status code 302

My status code response is 302, not 200. I think this has something to do with url redirecting? The explanations I found on google are either very technical or unhelpful.. Thanks.

Mark VonGyer
Mark VonGyer
21,215 Points

I don't see the question. Yes 300's are relevant to redirects.

Jacob Bender
Jacob Bender
15,300 Points

In the video he gets response 200, so I am wondering why I a getting 302's.

When I run the code, I get:

302
BODY: <html><body>You are being <a href="https://teamtreehouse.com/404">redirected</a>. </body></html>

instead of the info I am trying to get.

Update: Never mind, I am an idiot. had a typo in the url request.

Ekaterina Tokareva
Ekaterina Tokareva
5,310 Points

I've noticed, that when in get url I'm writing "http://teamtreehouse.com/" + username + ".json" - the response.statusCode is 200. And in case of "http://www.teamtreehouse.com/" + username + ".json" url value the response.statusCode is 301

2 Answers

@ekaterinatokareva2 i'm also having the same response from the server.

Make sure you are requiring https (NOT http), like so:

var http = require("https"); //this is correct

Likewise, make sure you are using the https url and NOT http:

var request = http.get("https://teamtreehouse.com/" + username + ".json", function(response){
  console.log(response.statusCode);
});

That should give you the 200 response.