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

491
Views
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
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!