Home > Software design >  Cannot delete an article in crud app (mongo, express, Nodejs)
Cannot delete an article in crud app (mongo, express, Nodejs)

Time:01-19

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? enter image description here

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>

This is my server.js file enter image description here

CodePudding user response:

Write your app.use(methodOverride("_method")); middleware before routing app.use('/articles', articleRouter)

  •  Tags:  
  • Related