Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Alex Villanueva
Alex Villanueva
3,063 Points

Error getting the profile

This is for course Build a Simple Dynamic Site with Node.js

I've spent at least 3 hours on this and would greatly appreciate any help you could give.

var Profile = require("./profile.js"); is included at the top. profile.js is included and has not been edited. I am checking usernames that do exist.

Error given is There was an error getting the profile for alexvillanueva.

function user(request, response) {
  var username = request.url.replace("/", "");
  if(username.length > 0) {
    response.writeHead(200, {'Content-Type':'text/plain'});
    response.write("Header\n");
    var studentProfile = new Profile(username);
    studentProfile.on("end", function(profileJSON){
      var values = {
       avatarUrl:profileJSON.gravatar_url,
       username:profileJSON.profile_name,
       badges:profileJSON.badges.length,
       javascript:profileJSON.points.JavaScript
      }
                  //Simple Response
  response.write(values.username + " has " + values.badges + " badges \n");
  response.end('Footer\n');
});
studentProfile.on("error", function(error){
  response.write(error.message + "\n");
  response.end('Footer\n');
});
}
}

1 Answer

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 33,545 Points

Hi Alex. When asking questions it is helpful to link to the video you are working on and also to post all of your code. I assume you are on this video. If so if you look at the question about this video you will see Steve's answer about the link on treehouse for profiles changing. if you change profile.js to this it should work.

var request = https.get("https://teamtreehouse.com/profiles/" + username + ".json",  function(response) {

Hope this helps and good luck. Post back to the community if you are still stuck.