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

202
Views
Fetch Post a number server body undefined

On the server I can't get my request.body.value but I don't know why. It is always undefined. I have already tried my other fetch function with a json. And it has worked and they are very similar.

app.use(express.urlencoded({
    extended: true
}));  
app.post('/async', (request, response) => {
    const size = request.body;
    console.log(size.value)
    let data = [];
    for (let i = 0; i < size.value; i++) {
        data.push(faker.fake("{{name.lastName}}" + " " + "{{name.firstName}}"))
    }
    response.send(JSON.stringify(data))
})
async function sendAsync(event) {
            event.preventDefault();
            let value = 15;
            let response = await fetch('/async', {
                method: "post",
                body: value
            });
            if (!response.ok) throw new Error(response.statusText);
            let name = await response.json();
            displayUserInfo(name);
        }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

your request.body is the whole value you sent body: value. it's not an object

1- deal with it as a value directly

app.post('/async', (request, response) => {
    const size = request.body;
    console.log(size) // here
    let data = [];
    for (let i = 0; i < size; i++) { //here
        data.push(faker.fake("{{name.lastName}}" + " " + "{{name.firstName}}"))
    }
    response.send(JSON.stringify(data))
})

or 2- send an object that has a property called value with the value you want

async function sendAsync(event) {
            event.preventDefault();
            let value = 15;
            let response = await fetch('/async', {
                method: "post",
                body: {value} //here
            });
            if (!response.ok) throw new Error(response.statusText);
            let name = await response.json();
            displayUserInfo(name);
        }

about 4 years ago · Juan Pablo Isaza Report
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!