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 2017 Building a Command Line Application Getting the Response Body

Get an undefined value returned.

I get an undefined error when I run the code below in the node.js workspace. Please assist.

// Problem: We need a simple way to look at a user's badge count and JavaScript points // Solution: Use Node.js to connect to Treehouse's API to get profile information to print out var https = require("https");

const username = "chalkers"; //Function to print messsage to console function printMessage(username, badgeCount, points){ const message = ${username} has ${badgeCount} total badges(s) and ${points} points in JavaScript; console.log(message); }

// Connect to the API URL (https://teamtreehouse.com/username.json) const request = https.get(https://teamtreehouse.com/${username}.json, response => {

                      console.log(response.statuscode);

//Read the data //Parse the data //Print the data

                      });

1 Answer

The methods in node,js follow a camelCase format. Try:

console.log(response.statusCode); // Capital C

That worked perfect. Thank you!