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 trialPatience B Ndlovu
5,650 PointsWe've been tasked to continue with this prototype site. Have a look in the index.js and routes.js file and familiarize y
pliz help me
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("./routes.js");
response.writeHead(200, {'Content-type': "text/plain"});
response.end("routes\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);
2 Answers
Colin Bell
29,679 Pointsthe request.url()
should be "/about"
and the response.end()
should be "About\n"
.
Don't forget to make the about function acccessible to other files by adding module.exports.about = about;
.
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;
toby lacson
12,499 Pointsmy answers are right but it says its wrong, what should i do
Patience B Ndlovu
5,650 PointsPatience B Ndlovu
5,650 Pointsthank you