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

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 37,901 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.