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 Populating User Information

Zack McCartney
PLUS
Zack McCartney
Courses Plus Student 266 Points

Why am I getting write after end error when running the code on my computer?

So, I followed along with the video, but when I run the code on my local machine, I keep getting "write after end" errors when I jump between different requests.

For example,

  1. Started the server
  2. Requested "/" --> the page showed up
  3. Requested "/chalkers" --> I saw a line saying "chalkers has x # of badges"
  4. Requested "zackmccartney2" (my username) --> server crashed;

And by crashed I mean: got an error in Chrome saying "localhost refused to connect"

In my console, I got this error: " events.js:141 throw er; // Unhandled 'error' event ^

Error: write after end at ServerResponse.OutgoingMessage.write (_http_outgoing.js:430:15) at Profile.<anonymous> (/Users/Zack/Desktop/Build a Simple Dynamic Site with Node.JS/stage_2_video_2/router.js:46:16) at emitOne (events.js:77:13) at Profile.emit (events.js:169:7) at ClientRequest.<anonymous> (/Users/Zack/Desktop/Build a Simple Dynamic Site with Node.JS/stage_2_video_2/profile.js:24:28) at ClientRequest.g (events.js:260:16) at emitOne (events.js:77:13) at ClientRequest.emit (events.js:169:7) at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:419:21) at HTTPParser.parserOnHeadersComplete (_http_common.js:103:23) "

I checked my code; everything seems to be ok (of course, seems is the operative word) I've restarted the server and run through this a few more times. I keep getting this error, but not in the same sequence. Sometimes, I can request a bunch of pages in a row before it cops out. Sometimes, only 2.

Does anyone have any idea why I keep receiving this error?

Thanks! Zack

Zack McCartney
Zack McCartney
Courses Plus Student 266 Points

Forgot to mention: My wifi's not the greatest right now; could this just be a connectivity issue?

Johan Marais
Johan Marais
15,920 Points

Could you share your code with us. It's easier to diagnose code if we can see it. :)

1 Answer

Zack McCartney
PLUS
Zack McCartney
Courses Plus Student 266 Points

hey Johan, thanks for responding, but today, I reran my code on a better connection and had no trouble at all, looks like all good. But thanks for that pointer, though, on sharing code; I'll keep that in mind for the future troubles that I'm sure are to come :)