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

301 error with HTTP, not HTTPS

Hey everyone,

While working through this step I kept getting a 301 error while using the http module, so I tried HTTPS instead and it worked fine. Later on in the steps however this causes some problems. Anyone else have similar issues/know why this is happening?

Thanks!

6 Answers

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi all,

DevOps just informed me that the site has flipped over all of the site to HTTPS. +1 for security. -1 for breaking things :/

Both http and https have similar APIs so simply swapping out http in your code to something like this

var https = require("https"); 

And renaming all references to http to https will solve the problem.

Remember to update your URLs to have https at the beginning.

Regards
Andrew

Seth Kroger
Seth Kroger
56,414 Points

FIX: node.js has a separate class for https requests that act virtually identical to the class for http requests.

Add the line at the top of profile.js with the other requires:

var https = require("https");

Then change the line making the request to:

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

and it will work.

Seth Kroger
Seth Kroger
56,414 Points

Did you add https in addition to http or replace it? https does have the requests and servers parts of http but doesn't replicate the http.STATUS_CODES[]. You need to require both in profile.js only, the rest just need http, and the only place you need to use https is to make the request for the profile.

That's exactly what I did actually! I got it all working, I just wanted to make sure there wasn't something silly I was missing as to why http was giving me a "permanently moved" error! I was just using HTTPS until I needed the STATUS_CODES, so I have both required now. I was hoping to understand why it was happening since other people seem to be able to do just fine with HTTP only.

Thanks!

Seth Kroger
Seth Kroger
56,414 Points

The "Permanently Moved" thing redirecting the links from http:// to https:// seems to be a pretty recent change to the site. Like within the last day or so.

Lido Fernandez
Lido Fernandez
10,556 Points

hi Seth,

I don't know if i get it right but I don't get why you have to require both http and https. How would be the final result? I tried myself and evently I get a 404 error.

__ROLLER__ Angel
__ROLLER__ Angel
25,606 Points

Thanks everyone for these helpful tips. I inspected my response with the dir method and it provided hints about the https solution.

chaz
chaz
25,372 Points

Switching everything over to https worked, however workspaces is noticeable sluggish, everything from typing, scrolling, to the responsiveness of the console. I'm assuming this is to be expected due to encryption?