I did below code in my API file but I don't understand how to manage below two async calls to execute the function in order can someone help me to resolve the issue or can I use promise to solve the issue.
Thanks in advance for the help.
function getDataFromBK() {
connection((db) => {
var comment = "";
db.collection('comment')
.find({
"appNo": appNo
}, {
"filename": fileName
})
.toArray()
.then((filelist) => {
/* response.data = filelist;
res.json(response);*/
comment = filelist[0].comment;
console.log("comment-->" + comment);
return comment;
}).catch((err) => {
console.log("err-->" + err);
return err;
})
});
filepath = path.join(__dirname, '../../uploads/output/' + req.body.appNo) + '/' + req.body.filename[i];
fileInfo.push({
"originalName": req.body.filename[i],
//"size": req.body.filename.size,
"b64": new Buffer(fs.readFileSync(filepath)).toString("base64"),
"comment": comment
});
}