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 trialellie adam
26,377 PointsFinally, in the index.js file, make sure that the about route is being handled by the HTTP server.
function about(request, response) { if(request.url == "/about") { response.writeHead(200, {'Content-type': "text/plain"}); response.end("About\n"); } }
module.exports.root = root; module.exports.contact = contact; module.exports.about = about;
I am stuck here. error message is:
You need to call the about
method on the imported routes
object.
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"});
response.end("About\n");
}
}
module.exports.root = root;
module.exports.contact = contact;
module.exports.about = about;
var http = require("http");
var routes = require("./routes.js");
http.createServer(function(request, response){
routes.root(request, response);
routes.contact(request, response);
}).listen(3000);
11 Answers
Brandon Dyal
16,544 PointsHave you tried declaring routes.about(request, response); in the createServer function like you did for root and contact?
Ryan Broughan
12,742 PointsFor the others skimming for the answer, I added formatting.
In the index.js file:
http.createServer(function(request, response){
routes.root(request, response);
routes.contact(request, response);
routes.about(request, response); // The missing line of code
}).listen(3000);
ellie adam
26,377 Pointsvar http = require("http"); var routes = require("./routes.js");
http.createServer(function(request, response){ routes.root(request, response); routes.contact(request, response); routes.about(request, response); }).listen(3000);
It is funny that same code passed today. I tried several times yesterday it didn't work.
Andrew Chalkley
Treehouse Guest TeacherThere may have been gremlins!
cathy mitchell
8,249 PointsEllie,
Don't feel alone!!!! I get that all the time. I spend half my time copy paste my code over and over until it finally takes it.
ellie adam
26,377 PointsI did.
error message is:
You need to call the about method on the imported routes object. What it mean by import route?
Andrew Chalkley
Treehouse Guest TeacherWhat Brandon Dyal should work. Can you paste in the code when you attempted that variation?
ellie adam
26,377 Pointslol
Arash Farahani
270 PointsDoes some one have the answer to this haha. I can't seem to get it either :(
ellie adam
26,377 PointsI passed the challenge with above code.
Arash Farahani
270 Pointshaha, just refreshed and it worked...weird.
ellie adam
26,377 Pointsgood!
Arash Farahani
270 PointsThank you, appreciate the help!
ellie adam
26,377 PointsGlad to help you :)