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 Handling Routes Review

Zubeyr Aciksari
Zubeyr Aciksari
21,074 Points

We've been tasked to continue with this prototype site. Have a look in the index.js and routes.js file and familiarize y

Hi guys, i am stuck in here, can someone please correct me? Thanks!

"We've been tasked to continue with this prototype site. Have a look in the index.js and routes.js file and familiarize yourself. In the routes.js, just like the other two functions create an about function for a /about route. Have it print out "About\n" to the response. Remember to make this accessible by other files."

routes.js
function root(request, response) {
    if(request.url == "/") {
        response.writeHead(200, {'Content-type': "text/plain"});
        response.end("Home\n");
    }
}

function contact(request, response) {
    if(request.url == "/contact") {
        response.writeHead(200, {'Content-type': "text/plain"});
        response.end("Contact\n");
    }
}
function about(request, response) {
  if(request.url == "/about")  {
    response.writeHead(200, {"Content-type" : "text/plain"});
    reponse.end("About\n");
  }
}

module.exports.root = root;
module.exports.contact = contact;
index.js
var http = require("http");
var routes = require("./routes.js");

http.createServer(function(request, response){
    routes.root(request, response);
    routes.contact(request, response);
}).listen(3000);

1 Answer

Hi Zubeyr,

You're missing the last part of the instructions "Remember to make this accessible by other files."

Currently, only 'root' and 'contact' have been exported at the end of the file.

You also have a typo with response in your about function

reponse.end("About\n");