Hi I am trying to make a crud app using Node Express and mongodb. But when I am trying to delete an article from my app it says it cannot delete. I checked all the code but cant find errors. Can anyone help please?

Delete route in my code is
router.delete('/:id', async (req, res)=>{
await Article.findByIdAndDelete(req.params.id)
res.redirect('/')
})
Link to delete an article is
<form action="/articles/<%=article.id%>?_method=DELETE" method="POST" >
<button type="submit" >DELETE</button>
</form>
CodePudding user response:
Write your app.use(methodOverride("_method")); middleware before routing app.use('/articles', articleRouter)

