Error status: 404 returned with PUT request using Node.js (express), Angular, and MongoDB Error status: 404 returned with PUT request using Node.js (express), Angular, and MongoDB mongoose mongoose

Error status: 404 returned with PUT request using Node.js (express), Angular, and MongoDB


Your api put request is targeting the wrong urlangular

this.http.put(`http://localhost:3000/api/posts/${postId}`, post)

backend

app.put("/api/post/:id", (req, res, next) => {

one is post the other its posts. they need to be the same.


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.