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

170
Vistas
I recieve an empty request.body on my nodejs server from my page

I´m using nodejs to make a server what connect with a DB and a simple website, i can do a GET fetch and i take the data, but when i do a POST fetch my server receive and empty request.body.I try 2 diferents versions of nodejs 12.16.1 and 16.10.0 also i use express and body-parser and i got the same result.

This is my config on the server site

const express = require('express');
const morgan = require('morgan');
const app = express();

const router = require('../routes/routes.js');
/**configuraciones */

app.set('port',3000);

app.use(morgan('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(router);


app.listen(app.get('port'), () =>{
    console.log("El server esta operativo ")
});

This is my code on website

var username = document.getElementById('user-reg');
var emailreg = document.getElementById('email-reg');
var btnReg = document.getElementById('btn-reg')
btnReg.addEventListener('click', sacarInformacion)

function sacarInformacion(){
    var user = username.value
    var email = emailreg.value
    var jsonString = `{"correo": "${email}", "nombre":"${user}"}`
    const options = {
        method : 'POST',
        mode: 'no-cors',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.parse(jsonString)
    }
    fetch('http://localhost:3000/to', options);
    console.log(JSON.parse(jsonString))
    //i catch in the console the data i pass on body
}

The main problem is that i used postman as API and i get the body on the server, but when i use it on website i get an empty body

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