Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Node.js Basics (2014) Building a Command Line Application Getting the Response Body

Asaf Tzarfaty
Asaf Tzarfaty
3,740 Points

Getting an error in the console.

While a node js course I'm writing this code:

function printPoints(userName, badgeCount,points){
  var message = userName+' has ' +badgeCount+' total badges and '+points+' in javaScrpt';
var http = require("http");

var request = http.get("https://teamtreehouse.com/asaftzarfaty.json", function(response){
  var body;
    body += chunk;

I'm getting this error:

treehouse:~/workspace$ node app.js                                                                                 
    throw new Error('Protocol "' + protocol + '" not                                                               

Error: Protocol "https:" not supported. Expected "ht                                                               
    at new ClientRequest (_http_client.js:55:11)                                                                   
    at Object.exports.request (http.js:31:10)                                                                      
    at Object.exports.get (http.js:35:21)                                                                          
    at Object.<anonymous> (/home/treehouse/workspace  
   at Module._compile (module.js:541:32)                                                                          
    at Object.Module._extensions..js (module.js:550:                                                               
    at Module.load (module.js:458:32)                                                                              
    at tryModuleLoad (module.js:417:12)                                                                            
    at Function.Module._load (module.js:409:3)    
   at Module.runMain (module.js:575:10) 

I really don't know how to handle this error.

1 Answer

5,950 Points

var request = http.get("https://teamtreehouse.com/asaftzarfaty.json", function(response){ console.log(response.statusCode);

you cannot use http to handle https.

var http = require("http"); 

you can change this into

var http=require('https');

hope this is helpful.