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 Making a GET Request with http

alex gwartney
alex gwartney
8,849 Points

statusCode 404 when requesting user name in node.js

So when i do a request on status code in node.js i get a 404 but not sure why my account is off private and is open to public so does any one have and idea whats going on here is my code.

//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 http = require("http"), user = 'Chalkley';

function printMessage(username, badgeCount, points){
  var message = username + ' has ' + badgeCount + ' total badges and ' + points + ' points in JavaScript.';
  console.log(message);
}

//Connect to the API URL (https://teamtreehouse.com/username.json)
var request = http.get('http://teamtreehouse.com/' + user + '.json', function(response) {
  console.log(response.statusCode);
  //Read the data
  //Parse the data
  //Print the data
});

2 Answers

Nathan Williams
seal-mask
.a{fill-rule:evenodd;}techdegree
Nathan Williams
Python Web Development Techdegree Student 6,851 Points

the user variable is off; you probably mean chalkers. You can also double check by just loading the URL in your browser. If you go to a user's profile page in the app, you can just add .json to the URL to see the raw data your program is getting :)

alex gwartney
alex gwartney
8,849 Points

thanks that was exactly what i needed.

Thanks for that, Nathan. You're a gentleman and a scholar.