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

253
Views
Express.js: undefined request.body
const express = require('express');
const cors = require('cors');

const app = express();
app.use(express.json())
app.use(cors());

app.post('/', (req,res) => {
    console.log(req.body);
    res.send('received')
})

app.listen(5000, console.log('Server is running on port 5000'));

I am trying to send data to the back-end but always getting undefined

enter image description here

I tried to you a parser but seems like just wrapping void into an object

enter image description here

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Posting as answer from my comment.

In the second image in postman you need to change the type dropdown from text to JSON, express.json() only parses the body when the header Content-type is set to "application/JSON" and changing that dropdown will automatically include that header.

Here are the docs if it helps explain why you get the empty object in the second image

over 4 years ago · Santiago Trujillo 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!