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

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

        studentProfile.on("error" , function(error){
            //show erros
module.exports.home = home;
module.exports.user = user;

1 Answer

Daniel Boisselle
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