6
axios.put('http://localhost:3000/api/userDatas/findUserAddProp',{
    params: {
        userId: "5bb8c3bd16bf1f515ce5b42f",
        prop: "questions",
        questionId: "5bb8c466cb49d8421c05eeda"
    }
});

Server

Userdatas.findUserAddProp = function(req, res, cb) {
    const queryId = req.query.userId;
    const propToUpdate = req.query.prop;
    const questionId = req.query.questionId;

    console.log("queryId: ", queryId);
    console.log("propToUpdate: ", propToUpdate);
    console.log("questionId: ", questionId);
    ...
}

Here is the the server output on the console.

queryId:  undefined
propToUpdate:  undefined
questionId:  undefined

Why is that happening i just passed all params to the server?

Henok Tesfaye
  • 8,287
  • 13
  • 47
  • 84

3 Answers3

3

the put method expects an extra parameter "data" (sent in request body):

axios.put(url[, data[, config]])

pass it as null and you're done:

axios.put('http://localhost:3000/api/userDatas/findUserAddProp', **null,** {
...
Dmitriy
  • 5,525
  • 12
  • 25
  • 38
walpod
  • 61
  • 3
1

You can open Axios Interface

put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;

The Put method recieve the config after the data so you can do:

axios.put('http://localhost:3000/api/userDatas/findUserAddProp',
  // Add null here in the data,
   null,
   // then you can give params in the config 
  { params: { /* your params goes here */ }
});
0

Did you try

req.params.userId

req.param is used to read Url Params like /user/:id whereas req.query is used to read query parameters like http:localhost:8080/api/users?id=123

Saqib Hussain
  • 125
  • 2
  • 6