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 trialcindy li
1,057 PointsStatus 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
19,810 PointsTreehouse switched all of their URLs from http to https a while back. Just use the https functions instead of the http and it works.
Ethan Fairweather
11,831 Pointsjust 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
Geoffrey Neal
30,298 PointsGeoffrey Neal
30,298 PointsJust remember that http.STATUS_CODES doesn't have an https version, so you will have to require both.
SC3 Rocks
33,474 PointsSC3 Rocks
33,474 PointsThanks guys, This resolved my 301 as well along with the other issues that came along with it.