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

238
Views
Fetch() data is not showing up on the server side

I am sending a simple fetch() to my server as follows:

eo.put = function (state) {
  
  console.log('PUT:state', state);

  let _id = encodeURIComponent(state._id);
  const options = { 
    headers: {'Content-Type': 'application/json'}, 
    method: 'PUT', 
    body: JSON.stringify(state)
  };
  fetch("/articles/put/" + _id, options )
    .then((response) => {
      console.log('RESPONSE', response);
      // you need to update the DOM here
    })
    .catch((error) => {
      console.error("DEBUG: fetch/PUT error", error);
    });
}

and I can verify that state is populated with the console.log().

However; on the server side req.body is not populated and shows undefined.

// .. snip
app.use('/articles', routes.articles);
// .. snip

// UPDATE OPERATIONS
router.route('/put/:_id').put((req, res) => {
  const _id = req.params._id;
  const obj = req.body;
  

      /*
      **
      ** req.body is empty
      **
      */
      debug && console.log('DEBUG: route: /articles/put : req.body', req.body);
    
      DBM.updateArticle(_id, obj).then(() => {
      }).catch((err)=>{
        res.status(500).send("DEBUG: database internal error", err);
      });
      res.end();
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Most likely you need to add a body-parser

const bodyParser = require('body-parser')

// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

// parse application/json
app.use(bodyParser.json())

// your routes...
about 4 years ago · Juan Pablo Isaza Report
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!