I do not have much experience with javascript and I am following a node.js book and in it there is the following code
function start(route, handle)
{
function onRequest(request, response)
{
var postdata='';
var pathname=url.parse(request.url).pathname;
request.setEncoding('utf8');
request.addListener("data", function(postDataChunkd)
{
postdata+=postDataChunkd;
});
console.log('Post data: ' + postdata);// <----------------------- HERE
request.addListener("end", function()
{
route(handle, pathname, response, postdata);
});
}
http.createServer(onRequest).listen(8124);
console.log('Server running on 8124');
}
exports.start=start;
The code is working as expected however the thing is that for me it seems a bit obscure that the variable postData is logged as the empty string in the middle of addListener("data"... and addListener("end"...
Could someone explain why the postData variable is logged empty despite a successful request?
Regards
Dan