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

295
Views
req.body is undefined - nodejs

Here is my html:

<form action='/new'  method='POST' >
  <span>pool name: </span>
  <input type="text" name="name" />
  <input type="hidden" name="imageSrcList" />
  <button type='submit' >Create new</button>
</form>

And here is the relevant JS:

var app = express()
app.use(fileUpload());
app.set('view engine', 'ejs')
app.use(express.static(__dirname + '/views'));

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

The console reads out:

TypeError: Cannot read property 'name' of undefined

I have tried with console.log(req.body) and this also is undefined.

Thanks in advance!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You're missing the body-parser middleware which is necessary to have req.body set to a value. Express doesn't come with this by default and will need to be installed via NPM npm i --save body-parser

const bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended: true}))
about 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!