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 trialevanritscher
10,209 PointsWhat is the data parameter?
Andrew mentions the different methods that we can use for handling the POST data and mentions the differences between request and response but to be honest I found it a bit convoluted.
He writes:
request.on('data',function(postBody)){}
But I don't understand where he's getting the term 'data' and I can't seem to find it referenced in the http docs section of nodejs.
Is "data" just a placeholder for something else?
Rather, what exactly is the 'stream' that is referenced? Why do we move from http to stream? Is this always the case?
1 Answer
Steven Parker
231,248 PointsThe term 'data' is the name of the event.
The .on() method establishes a handler for an event, and in this case the name of the event is 'data'. The data event is fired when a block of data becomes available on an incoming stream. The second argument to .on() is the function that will be called when the data is available.