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

122
Views
Body send but not received

Hey i use a react app for call a express app:

fetch('/api/sendmail', {method: 'POST', body: JSON.stringify(payload) })

Payload =

    const payload = {
        fsdfdsdfsdfsdsfa: 1,
        b: 2
    };

On express app i try to get body content:

app.post("/api/sendmail", (req, res) => {
   console.log(req.body)
   res.json({ message: 'aa' });
});

but console.log(req.body) return undefined

How i can resolve that.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I'd assume you simply missing something like this in your init file:

app.use(bodyparser.json())

Also try adding Content-Type: application/json as your request header

about 4 years ago · Juan Pablo Isaza Report

0

I think for express to be able to parse POST requests you need a body-parser middleware.

    var express = require('express')
    var bodyParser = require('body-parser')
    
    var app = express()

    var urlencodedParser = bodyParser.urlencoded({ extended: false })

    app.post('/login', urlencodedParser, function (req, res) {
        res.send('welcome, ' + req.body.username)
    })

You will have to install "body-parser" though. I heard express comes with it's own body-parser now but I have no info on that so you will have to read the docs

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!