I am fairly new to using Express and I am trying to set up the Delete function for my database. I am using the MERN stack. All of my CRUD operations work when I test them with Insomnia, except for the Delete operation.
This is the code block that seems to be giving me a problem.
router.route('/:id').delete((res, req) => {
Post.findByIdAndDelete(req.params.id)
.then(() => res.json('Post deleted'))
.catch(err => res.status(400).json('Error: ' + err));
});
RETURNS: TypeError: Cannot read property 'id' of undefined
The thing that is throwing me is that this code block grabs the req.params.id without problem.
router.route('/:id').get((req, res) => {
Post.findById(req.params.id)
.then(post => res.json(post))
.catch(err => res.status(400).json('Error: ' + err));
});
If someone could help me out I would greatly appreciate it.