Error status: 404 returned with PUT request using Node.js (express), Angular, and MongoDB
It seems like you are trying to update one post's Record so you can simply try this
router.put('/api/post/:id', async (req, res, next) => { return Post.updateOne({ _id: req.params.id }, { $set: { title: req.body.title, message: req.body.message } }) .then(result => res.json(result)) .catch(err => console.log(err))});
There is no need to create a new Post because you are trying to update an existing record based on the id
and also you are sending routs path like api/post
but you are getting a response from the server api/posts
so check your route path as well.