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 trial

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,239 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.