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 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");

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")

module.exports.home = home;
module.exports.user = user;
Steven Parker
Steven Parker
218,813 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.