0

I am trying to understand promises and from what I can understand, there are numerous way of using them. When do I use a promise and when do I use a callback like in the example below? I would like to know the difference here, since from what I can tell, they do pretty much the same job in this example.

1

await req.session.destroy().promise().then((data) => {
        console.log(data);
    }).catch((err) => {
        console.log(err);
    });

2

req.session.destroy((err) => {
    if (err) {
       console.log(err);
    } else {
      console.log('Session successfully destroyed');
   }
});
Gustav Vingtoft
  • 355
  • 2
  • 16

0 Answers0