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 User Route

cant get this to behave properly..........help!

so i've written these two handlers:

function home(request , response) { // if URL == "/" && GET // show search if(request.url === "/") { response.writeHead(200, {'content-Type': 'text/plain'}); response.write ("Header\n") response.write ("Search\n") response.end('Footer\n'); } // if URL == "/" && POST // redirect to / :username }

// Handle HTTP route route GET / :username i.e. /chalkers function user(request, response) { //if URL == "/....." var username = request.url.replace("/", " "); if (username.length > 0) { response.writeHead(200, {'content-Type': 'text/plain'}); response.write ("Header\n") response.write ("username + \n") response.end('Footer\n');

    // GET JSON from treehouse

// on "END" 
    // shoiw profile
// on "error"
    // show error


and i keep getting this error!! :

Error: write after end at write_ (_http_outgoing.js:622:15) at ServerResponse.write (_http_outgoing.js:617:10) at Object.user (C:\Users\ellis.corio\Desktop\Dev\Node\server\router.js:21:12) at Server.http.createServer (C:\Users\ellis.corio\Desktop\Dev\Node\server\app.js:13:10) at emitTwo (events.js:126:13) at Server.emit (events.js:214:7) at parserOnIncoming (_http_server.js:619:12) at HTTPParser.parserOnHeadersComplete (_http_common.js:112:17)

Any Ideas/suggestions welcome.