Hi! I recently learned about 'callback hell' and I would like to rewrite my routes to use promises instead of callbacks but I have troubles understanding how to actually write it.For instance, I have this route:router.post("/books/:id", (req, res) => { let { id } = req.params Books.findByIdAndRemove(id, err => { if (err) { return res.status(500).json({ err: "Book ID not found" }) } return res.redirect("/home") }) })Is there a resource out there that can help me understand how to achieve this? I don't understand where I should use my 'then' keyword and so on.Thanks in advance!
Submitted November 25, 2017 at 04:16PM by tradehodlrepeat
No comments:
Post a Comment