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 Redirection Headers in Node.js

why did he not also use request.on("end", ... ) to get the url query string?

In the Node.js Basic course, he explained that the 'data' event gives data in parts which is why we also need the 'end' event to get the complete data. I am guessing the reason why he is not using it is because the query string is so short that the data is send in one go? Or perhaps the response.end() is the same as the 'end' event? Or maybe it is something else?

1 Answer

Steven Parker
Steven Parker
231,248 Points

This implementation relies on the data being complete in one package, which is adequate for the particular info being requested.. A more generic and robust implementation would just collect on "data" events, and respond on the "end" event as you saw in the previous example.

The call to "response.end()" completes and sends the outgoing message and is not related to the "end" event of the incoming one.

thanks again steven.P