DELETE ROUTE

 INDEX.EJS

   </form>
      <form method="post" action="/chats/<%= chat._id %>?_method=delete">
        <button>Delete</button>
      </form>

INDEX.JS

/ DELETE ROUTE
  app.delete("/chats/:id",async(req,res)=>{
    let {id}=req.params;
    let deletedChat=await Chat.findByIdAndDelete(id);
    console.log(deletedChat);
    res.redirect("/chats");
  })




Comments

Popular posts from this blog

CREATE ROUTE

Schema type options