Add WRAP ASYNC

const wrapAsync = require("./utils/wrapAsync.js");

WRAPASYNC.JS IS CREATED IN UTILS FOLDER

module.exports = (fn) => {
  return function (req, res, next) {
    fn(req, res, next).catch(next);
  };
};

 

app.post("/listings", wrapAsync(async (req, res, next) => {

    const newListing = new Listing(req.body.listing);
    await newListing.save();
    res.redirect("/listings");

}));
SERVER STILL RUNS


Comments