0

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?

Ivan Beldad
  • 2,285
  • 2
  • 21
  • 33

1 Answers1

0

I happened to solve it by my own, here's what I did (in case anybody else faces the same problem). Basic info: Server: Ubuntu with express server Server Stack: nodeJs with Mustache (handlebars) Frontend: bootstrap, angular

I had to make an get API but that IMAP library has its own events based on which the result is returned, so simply using request/response in express I did following:

app.get('/getBox', (req, res) => {res.send({status: true});});

so sending response when imap end event is triggered was the only thing that worked.