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

604
Views
Node.js React node-fetch empty body post

I am trying to do a simple post from Reactjs to a node.js server using node-fetch; however, the body of my request is always empty (I have not been able to come up with any configuration which results in a non-empty body). I have read seemingly every stackOverflow question about this and none solves my predicament, sadly. Here is my reactjs code:

fetch('http://localhost:3000/sayhello/', {headers: new Headers({
            'Content-Type': 'application/json'
        }), method: 'POST', body: {"nose":"bop"} })
        .then(function(res) {
            return res.json();
        }).then(function(json) {
            console.log(json);
        });

And my server.js: ... import BodyParser from 'body-parser';

app.use(BodyParser.urlencoded({extended : true}));
app.use(BodyParser.json());
app.post('/sayhello/', function(req, res) {
  console.log(req.body);
  res.send(req.body);
});

The console always gives an empty body, and the response is always undefined. This happens too when rather than JSON I just post a string as body. Any ideas?

Thanks

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Not to worry friends it seems I have figured it out. I was missing JSON.stringify in body. I hope this helps someone sometime, so they avoid pulling out as much hair as I did :)

about 4 years ago · Santiago Trujillo 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!