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

Samarth Shrivastav
PLUS
Samarth Shrivastav
Courses Plus Student 3,285 Points

Body not showing up

Greetings! I have entered absolutely the same code as in the video, but I don't get the Body in the output. Just the "Hello World!" and statusCode is printed but not the Body at all. The console doesn't show any errors at all, and I've tried waiting but nothing shows up. https://w.trhou.se/ao3vy859bp Thank You! Regards, Samarth

3 Answers

Hi Samarth,

This post will probably solve your issue. The short answer is that Treehouse switched to https (vs http) a couple of months ago, and you simply need to change your urls and require statement to reflect that.

Best, Cena

Jan Kuppens
Jan Kuppens
4,154 Points

This has worked for me. Thanks. Change all http to https: var http > var https require ("http") > require ("https") http.get > https.get http://team... > https://team..

Weird, it's working for me. Anyway, try this:

https://teamtreehouse.com/community/301-error-with-http-not-https
Samarth Shrivastav
Samarth Shrivastav
Courses Plus Student 3,285 Points

Greetings! Cena!

Whoops! Sorry, it started just as you posted the second answer. Works fine now. Thank You For Your Help! Wish You Greater And Greater Health!

Thank You! Regards, Samarth

I just did

response.on('data', function(chunk) {
      console.log('BODY: ' + chunk);

heres the rest

var http = require('https');

var request = http.get('https://teamtreehouse.com/robohat.json', function(response){
    console.log('status code:', response.statusCode);
    console.log('headers:', JSON.stringify(response.headers))
    response.setEncoding('utf8');
    response.on('data', function(chunk) {
      console.log('BODY: ' + chunk);
    });
});

request.on("error", function(error){ console.error(error.message); });