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 trialpastry assassin
Full Stack JavaScript Techdegree Student 11,693 PointsRoutes Node.JS code challenge
I'm not entirely clear on what the code challenge is asking me to do. It's saying that I need to create an about function to print out "About\n" inside of the routes.js file and add it to the abouts route. Can someone help me with this?
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");
}
}
module.exports.root = root;
module.exports.contact = contact;
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
Steven Parker
231,269 PointsTake a look at the other two functions already there, particularly the one that implements "contact". What the challenge wants you to do is make a function just like that, but for "about" instead of "contact". Use the contact function as a template and it you should not have much trouble.
Don't forget to add it to the exports down at the bottom, also.
pastry assassin
Full Stack JavaScript Techdegree Student 11,693 Pointspastry assassin
Full Stack JavaScript Techdegree Student 11,693 PointsAha! Thanks