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 trialBryan Woodard
5,757 PointsWhy does code not work without "response.end('some string')?"
I wrote the code exactly as it appeared in this exercise yet on every test I do, the browser hangs for about 30 seconds and eventually just times out. I checked the network tab and it says the request failed.
To get my code to work, I have to add 'response.end("something");' to all of my callback functions.
Why is it that Chalkers' code loads nearly immediately with no hang, and mine does not?
2 Answers
Seth Kroger
56,414 Pointsresponse.end() is always needed to let the server know we're done building the response send, anything left and close browser connection. It doesn't need an argument but is it needed to wrap thing up. You'll see that Andrew goes back near the end of the video and adds response.end()'s after the view calls.
Nikhil Khandelwal
9,371 PointsThe explanation on nodejs.org is : response.end([data][, encoding][, callback]) "If data is specified, it is equivalent to calling response.write(data, encoding) followed by response.end(callback)". All the argument in the end function are optional.
As you have written response.end("footer \n"); response.end("end")//delete if necessary ----- " ; " missing at end of function response.end("end!"); //delete if needed
Hope this help
Bryan Woodard
5,757 PointsBryan Woodard
5,757 PointsHere is a snapshot of my workspace https://w.trhou.se/zfgob542bv