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 trial

JavaScript Build a Simple Dynamic Site with Node.js Handling Routes in Node.js Handling Routes Review

can i get some help or do i just leave this platform? i haven’t had an instructor able to help at all

where do people get help from? other students? I have to look to other students to get help? i can’t get help in a learning platform? i don’t understand? outdated information, and i’m supposed to know it’s not working and outdated, and i should find a solution, even though i’m learning all of this. this is completely ridiculous.

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

// Import any necessary modules if required

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

module.exports = {
    about: about,
    // You can add other route functions here if needed
};


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

http.createServer(function(request, response) {
    if (request.url === "/") {
        routes.root(request, response);
    } else if (request.url === "/contact") {
        routes.contact(request, response);
    } else if (request.url === "/about") {
        routes.about(request, response); // Handle the /about route
    } else {
        response.writeHead(404, { 'Content-Type': 'text/plain' });
        response.end("404 Not Found\n");
    }
}).listen(3000);

1 Answer

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,708 Points

Try starting with JavaScript Basics. Spamming the Community with posts of frustration helps no one.

Start the course over. Great advice.