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 HTTP Methods and Headers Dealing with the POST Body

Downloaded project files, changed nothing, app is crashing.

Hi folks,

I started this course several months ago, using my local machine to follow along. I took some time away and came back this month to start again, but now whenever I start the server, and make a request to the /:username endpoint, node crashes with the following output:

      throw er; // Unhandled 'error' event                                                                     

Error: write after end                                                                                         
    at write_ (_http_outgoing.js:622:15)                                                                       
    at ServerResponse.write (_http_outgoing.js:617:10)                                                         
    at Object.view (/home/treehouse/workspace/renderer.js:19:11)                                               
    at Profile.<anonymous> (/home/treehouse/workspace/router.js:43:16)                                         
    at emitOne (events.js:116:13)                                                                              
    at Profile.emit (events.js:211:7)                                                                          
    at IncomingMessage.<anonymous> (/home/treehouse/workspace/profile.js:38:36)                                
    at emitNone (events.js:111:20)                                                                             
    at IncomingMessage.emit (events.js:208:7)                                                                  
    at endReadableNT (_stream_readable.js:1064:12)

I tried to do some debugging on my end, thinking I had accidentally changed something in one of the files, but nothing changed. So I downloaded the project files in the zip. I opened the appropriate video directory (which is /stage_4_video_2_finish I believe) and without touching a file started the server with node app.js and tried to visit the /:username endpoint, using chalkers as the video does and the app crashes with the exact error as above, and nothing shows in the browser.

Finally, I created a brand new workspace from the video page, and again without editing a file started the app with node app.js clicked the preview eyeball, selected port 3000 and appended /chalkers to url. The app again crashed with the exact same error.

Anybody know what's going on?

Edit: I should clarify I also tried using my own username only to have the crash occur again. I can successfully visit the https://teamtreehouse.com/chalkers.json url and see the relevant JSON data so it's not that the call is being done incorrectly.

1 Answer

Robert Manolis
Robert Manolis
Treehouse Guest Teacher

Hi Dylan, thanks for reaching out about this. To get the full final working version of the app, use the stage_4_video_3 folder, and follow along with the steps in this second to last video. For the app to work as it should, you'll need to add the code demonstrated in the above video to the last set of project files, stage_4_video_3. Then, when pointing your browser at http://localhost:3000/, the app should load, and you should be able to put chalkers or your own username in the input, and then clicking search will redirect the page to the result page that displays the user info. I just tested this and it does work.

If the app crashes for you after doing all that, I would recommend double checking your Node version, since you've been away for a while. You can run node -v in the terminal to check your current version. And here's a link to where you can download the latest stable version of Node, if you need it. If you do update from there, grab the LTS version, not the Latest Features one.

If you're still having trouble after that, go ahead and respond in this thread. I'll keep an eye out for that. :thumbsup: