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