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 Handling Parsing and Status Code Errors

Status code 301 for Node.js exercise

My practice version of this exercise returns a status code 301 ("Moved Permanently") for the profile I'm trying to access. I seem to have the same code as the example video and can't figure out what I'm doing wrong.

2 Answers

Roy Penrod
Roy Penrod
19,810 Points

Treehouse switched all of their URLs from http to https a while back. Just use the https functions instead of the http and it works.

Geoffrey Neal
Geoffrey Neal
30,298 Points

Just remember that http.STATUS_CODES doesn't have an https version, so you will have to require both.

Thanks guys, This resolved my 301 as well along with the other issues that came along with it.

just change var http = require("http") to var https = require("https"). Make sure to make those changes to the rest of the code as well. For example, my code original code connecting to the teamtreehouse api was ```var request = http.get("http://teamtreehouse.com/" + username + ".json", function(response){

console.log(response.statusCode); //Read the Data //Parse the Data //Print the Data })```

so your new code should look like

```var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response){

console.log(response.statusCode); //Read the Data //Parse the Data //Print the Data })```

Hope that helps