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 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
218,583 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