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 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.