Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
Axios + Express | Empty req.body (solved)

// START EIDT:

Solution was (thanks to mr. Hawkeye @robertklep) the name "body" in my post request in axios on the client side. Apparently you cannot name the body in axios post request anything but data, even though it's a reference passed from a parameter or similar.

// END EIDT:

I'm currently building an application with React as the frontend and Express as backend.

For API calls I'm using axios. My APIhas been working fine, but all of the sudden with no obvious change my post request body is not being sent to the backend.

In my index.js I had the following:

app.use(bodyParser.json());

but also tried with

app.use(express.json())

Client side function calling my post request:

 const checkForExistingUserData = async () => {
        if (user) {
            const body = {
                caseId: user['caseId']
            }

            await postRequest({request: body}, commonApiLocations["userDataLookUp"])
    }
}

My client side call is being call this way:

export function postRequest(body, url) {

        console.log(body) // Logs correct body with my data inside

        const config = {
        method: 'post',
        url: masterEndPoints['expressEndPoint'] + url,
        headers: {
            'Content-Type': 'application/json',
        },
        body // should be called "data" (see edit in top)
    };
    return axios(config);
}

Express route endpoint function:

route.post('/api/users/checkExistingUserData', async (req, res) => {

    try {
        const request = req.body.request;

        console.log("request: ", request); // Gives undefined

        if (request['caseId']) {
            let result = await checkIfExist(tableNames['TableName'], {'caseId': request.caseId})
            res.status(200).send(result);
        } else {
            res.status(200).send(false)
        }
    } catch (error) {
        res.status(500).send('En error occurred on the server')
    }
});

When I console.log on on the client side I see my request with the data that I expect to see.

When I console.log on the server I get an undefined.

When I console.log req.body I get "{}"

Any reasons for this error? I'm completely dumbfounded by this.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!