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 trialMatt Yost
Full Stack JavaScript Techdegree Student 13,976 PointsBODY: NaN
When I run the application in the console I do not get any of the body text.. Just BODY: NaN. Maybe I have not looked thoroughly enough, but I can't seem to find the answer anywhere. Any help would be greatly appreciated.
Thanks.
//Connect to API URL
var request = https.get("https://teamtreehouse.com/" + username + ".json", function(response) {
console.log(response.statusCode);
//Read data
response.on('data', function (chunk) {
console.log('BODY: ', + chunk);
});
//Parse data
//Print data
});
request.on("error", function (error) {
console.error(error.message);
});
Luciano Bruzzoni
15,518 Pointswelcome!
2 Answers
Luciano Bruzzoni
15,518 PointsHey, try taking out the + sign on your console.log function. You can either separate your arguments with a comma or do it all together by adding the strings with the + sign. In this case, you have the + sign after the comma, so it's thinking that there's something to add, and since there is nothing before it, it returns NAN. so you can do console.log("BODY: " + chunk); or console.log("BODY: ", chunk);
Hope that solved the issue!
Thomas Katalenas
11,033 Pointshere's mine
var http = require('https');
var user = 'robohat'
var request = http.get('https://teamtreehouse.com/' + user + '.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);
});
JSON.stringify(response.headers) that is what got the text going I think, and setEncoding.
Matt Yost
Full Stack JavaScript Techdegree Student 13,976 PointsMatt Yost
Full Stack JavaScript Techdegree Student 13,976 PointsThanks a bunch!