Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

605
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda