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 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';
console.log(message); 
}
var http = require("http");

var request = http.get("https://teamtreehouse.com/asaftzarfaty.json", function(response){
  console.log(response.statusCode);
  var body;
  response.on("data",function(chunk){
    body += chunk;
});
  response.on("end",function(){
              console.log(body);
});
});

I'm getting this error:

treehouse:~/workspace$ node app.js                                                                                 
_http_client.js:55                                                                                                 
    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

jayshi
jayshi
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.