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

406
Views
node.js express req.body undefined
var express = require('express'); 
var app = express(); 
var PORT = 3000; 

const bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}));
 
app.post('/', function (req, res) { 
  console.log(req.body); 
  console.log(req.body.username);
  res.end(); 
}); 

app.listen(PORT, function(err){ 
  if (err) console.log(err); 
  console.log("Server listening on PORT", PORT); 
});

Test by postman: Post: http://localhost:3000 { "username":"userabc", "password":"passwd1234" }

But, the result is: {} undefined

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try setting Content-Type: application/json in the request headers

about 4 years ago · Juan Pablo Isaza Report

0

You need to set Content-Type as application/json on the request.

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!