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

Rodrigo Valladares
Rodrigo Valladares
9,708 Points

ReferenceError: Profile is not defined

console says ReferenceError: Profile is not defined. Do you see my mistake ?

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


function home(req , res){
    //if url == "/" && GET
     if(req.url === "/"){

    res.setHeader('Content-Type', 'text/plain');
    res.write("Hola Amigos")
    res.write("Footer\n");
    res.write("Pagina!!\n");
    res.end('Hello World\n');
   }
}
       //if url =="/" && POST
       //Redirect to /:userna}
   // handle HTTP route GET /: username i.e /rodrigo
    function user(req , res){
        var username = req.url.replace("/", "")
        if (username.length > 0 ){
        res.statusCode = 200;
        res.write("Hola Amigos")
        //ge json from Treehouse
        var studentProfile = new Profile(username);
        //on end
        studentProfile.on("end" , function(profileJSON){
            //Show profile
            var values = {
                avartarUrl : profileJSON.gravatar_url,
                username: profileJSON.profile_name,
                badges: profileJSON.badges.length,
                javascriptPoits : profileJSON.points.JavaScript ,
            }
            //simple response
            res.write(values.username + values.badges + " puntos \n");
            res.end("footter")
        }); 


        studentProfile.on("error" , function(error){
          res.end("footter")
            //show erros
        });
        }
    }
module.exports.home = home;
module.exports.user = user;
]

1 Answer

Daniel Boisselle
seal-mask
.a{fill-rule:evenodd;}techdegree
Daniel Boisselle
Front End Web Development Techdegree Student 17,438 Points

Are you exporting profile.js correctly? Are you sure the file path is correct? What line is the error coming from?

There really isn't enough information here

Maybe line one also should be 'Profile' since you're using it as a constructor when assigning it to studentProfile.

Rodrigo Valladares
Rodrigo Valladares
9,708 Points

well, I think that I already have the solution, it is "var profile" on the line 1 should be "var Profile" but thanks. It was a so hard to find