I'm trying to make simple logger for nodejs to handle post and get request also, but I've got problem, because of the non blocking feature of node-js, the parameters is print after the system print the response log here is my code
process.stdout.write(createReqFormat(req));
if(req.method !== 'GET') {
var form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files){
process.stdout.write('\n Parameters:' + util.inspect(fields));
});
}
res.on('finish', function(){
process.stdout.write(createResFormat(res));
});
next();
for now I only print parameter for post parameter, but this already killing me.
Started POST /post for 127.0.0.1 at Mon Apr 27 2015 09:08:36 GMT+0700 (WIB)
Completed 200 OK
Parameters:{ one: '1', kals: '123', test: '1233', 'test[123]': 'dfjksdjf' }
how to make it print in the right order?
thank you