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 trialThomas Katalenas
11,033 Pointspostbody? where is that coming from?
sorry I didn't see the variable defined..
1 Answer
Sam Hall
Courses Plus Student 8,636 PointsHi Thomas,
I'm learning as I go here, but this is what I understand is happening:
When the POST request is received it fires a "data" event.
We are attaching an event listener to this, so that a callback function executes when the post request data is received:
request.on("data", function(postBody){
console.log(postBody);
});
So, when the server has received the POST request, it will trigger the callback function. By default the data event always passes a parameter into the function: the chunk of data that has been received.
postBody is the simply the name that Andrew has chosen to use for the chunk of data that is passed into the callback function when the "data" event is triggered. It's the name we use to reference it if we want to log it to the console, convert it to a string, etc.
The variable doesn't need to be defined because it is sent by the "data" event.
Hope that helps.
Sam