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!

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

Aaron Hill
Aaron Hill
9,732 Points

Https Protocol error when following along

In the node.js course i'm on the step where we require http, this is my code:

var http = require("http"); var username = "aaronhill3";

function printMessage(username, badgecount, points) { var message = username + " has " + badgecount + " total badge(s) and " + points + " points " ; console.log(message); }

//Connect to API Url var request = http.get("https://teamtreehouse.com/" + username + ".json", function(response){ console.dir(response); //Read the data from the response //parse data //print the data out


When I run the code I get a protocol error:

throw new Error('Protocol:' + options.protocol + ' not supported.');
Error: Protocol:https: not supported.
at Object.exports.request (http.js:1845:11)
at Object.exports.get (http.js:1852:21)
at Object.<anonymous> (/home/treehouse/workspace/app.js:13:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3

I triple checked my code and I still have no idea why this is happening, any help would be greatly appreciated.

1 Answer

Hugo Paz
Hugo Paz
15,622 Points

Hi Aaron,

It might be that you are using different protocols. You are requiring http but the request url is https.

Try replacing this - var http = require("http");

with this - var https = require("https");

remember to change the name in your code as well.

Aaron Hill
Aaron Hill
9,732 Points

Hi Hugo!

That totally worked! Thanks man! I should have realized, it seems so obvious now.