I have the following request with axios :
axios.post(`${baseURL}/test/updateInProcess/`, {
params:{
id: _id
}
});
But when my API with Express and Mongoose receives the request, it always sends undefined in that id, here I receive it:
exports.updateInProcess = (req, res, next) => {
const { id } = req.query;
console.log('id: ' + id);
}
Departure:
id: undefined
When I make the request with the parameters in Postman if the req.query
. When I do it with axios the request is carried out but it doesn't do what it should because it sends undefined
.
It is because you are sending an object like this in the post
And in backend you are trying to read the object like so
I imagine that you intend to use
params
how it is used in an axiosget
request , but in post, the object that you put as the second parameter of the post function is directly what you are going to send to the api, therefore what you are sending is an object like the first one I quoted you and you should send one like the second one.So: