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 Creating a Basic Template Engine in Node.js Reading from Files

aditigreen
aditigreen
6,730 Points

I am getting an unhandled error event after viewing the webpage

After I run the app.js file, I view the webpage. I come back and in the console, I get this error message: Server running at port: 3000
events.js:160
throw er; // Unhandled 'error' event
^

Error: write after end
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:426:15)
at /home/treehouse/workspace/renderer.js:8:11
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:439:3)
treehouse:~/workspace$ node app.js
Server running at port: 3000
events.js:160
throw er; // Unhandled 'error' event
^

Error: write after end
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:426:15)
at /home/treehouse/workspace/renderer.js:6:11
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:439:3)

To spare some people with a similar problem some time of frustration: One possibility , apart from the obvious .end in the wrong place, is that you set the if(username.length > 0)-statement of the user-function in the router.js file to if(username.length >= 0)

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

For an error message this one is fairly straight-forward, "Error: write after end". Once you call response.end() you can write to it anymore because the response is supposed to be closed out after that. Calling response.write() after that causes the error.

You can post your code if you still need help finding the problem.