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

492
Vistas
an empty object arrives in my backend server when i send from my frontend

An empty object arrives in my backend server when I send from my frontend.

My backend server should work fine as I tested it with postman. When I send the following JSON via postman I get a 200 response.

{"email":"tom@gmail.com","password":"123456"}

I have a problem when I send the object via my frontend-code to my backend. The backend server crashes because it recieves an empty object. Why is that?

When i console.log enteredUsername, it's not empty

console.log(enteredUsername, enteredPassword);
    let url = "http://localhost:4000/"
    fetch(url, {
      method: 'POST',
      body: JSON.stringify({
        email: enteredUsername,
        password: enteredPassword
      }),
      headers: {
        'Content-Type': 'application/json',
      },
      mode: 'no-cors'
    }).then(res => {
        if (res.ok) {
          return res.json();
        } else {
          return res.json().then((data) => {
            let errorMessage = 'Authentication failed!';
            // if (data && data.error && data.error.message) {
            //   errorMessage = data.error.message;
            // }

            throw new Error(errorMessage);
          });
        }
      })
      .then((data) => {
        console.log(data);
      })
      .catch((err) => {
        alert(err.message);
      });
    
  }

This is the code from my backend server. When i console.log user, it's empty

router.post('/', async (req,res)=>{
    console.log(req.body);
    const result = await data.addUser(req.body);
    res.send(result);
});

this is the method addUser:

async function addUser(user){
    const connectionDB = await connection.getConnection();
    
    console.log(user);
    user.password = bcrypt.hashSync(user.password,8);

    const result = await connectionDB.db('my-website')
        .collection('users')
        .insertOne(user);
    
    return result;
}

I get this error in my console of my browser:

POST http://localhost:4000/ net::ERR_CONNECTION_RESET

Thank you very much for helping me.

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