I'm trying to fetch all the mails from an inbox in nodejs and i'm using this library IMAP, I was successful in getting all the mails in my local machine, now I want to provide it as an get API, so i'm using express server and created a get url but the problem is that the IMAP library has its own callback mentioned below:
imap.once('end', function() {
console.log('Connection ended');
res.send(JSON.stringify({data: inboxesVals});
});
And I don't know if we can put the whole library code including callback above in that GET api function block, so how do I wait for the IMAP library to fetch the results and return the response?