I've node app with function that inside call to to other two function,I want to use some async behavior for it,what is recommended to use in this case. example will be very helpful.
function myFunction(req,res){
//from here this is the first place which I want to use warp in function
var dataChunks = [],
dataRaw,
data;
req.on("data", function (chunk) {
dataChunks.push(chunk);
});
req.on("end", function () {
dataRaw = Buffer.concat(dataChunks);
data = dataRaw.toString();
console.log(data);
//here is the second code which I want to warp in function and call after the first function
var filePath = 'C://test.txt';
var writeStream = fs.createWriteStream(filePath, {flags: 'w'});
writeStream.write(data);
res.status(200).send('ok');
})
}
one more thing,as I saw until now async is how the node framework working and to add additional libarary like Q is not overkill?