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 Build a Simple Dynamic Site with Node.js Handling Routes in Node.js Populating User Information

There was an error getting the profile for chalkers. (Unauthorized)

When trying to request /chalkers information I receive this message: "There was an error getting the profile for chalkers. (Unauthorized)"

var Profile = require("./profile.js");

function home (req, res){
  if (req.url === "/")  {
    res.writeHead(200, {'Content-type':'text/plain'});
    res.write("Home header\n");
    res.end("Goodbye");
  }
}

function user (req, res) {
  var username = req.url.replace("/", "");
  if(username.length > 0) {
    res.writeHead(200, {'Content-type':'text/plain'});
    res.write("Profile 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,
        javaScriptPoints: profileJSON.points.JavaScript
      }
      res.write(values.username + " has " + values.badges + " badges\n");
      res.end('Profile Footer\n');
    });

    studentProfile.on("error", function(error){
      res.write(error.message + "\n")
      res.end('Footer\n');
    });
  }
}


module.exports.home = home;
module.exports.user = user;
Steven Parker
Steven Parker
231,236 Points

Other parts of the projected needed to replicate the issue are not included here.
To share the entire project, use the snapshot function in the workspace and provide the link to that.