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

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