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

646
Views
req.body returning empty object (I've included bodyparser)

I'm new to backend javascript and I have a form that on submit is supposed to show the submitted object, but it's displaying an empty object instead. I've included body-parser so I'm not sure where the issue is. Here is my app.js file:

const express = require("express");
const app = express();
const mustacheExpress = require("mustache-express");
const bodyParser = require("body-parser");
const pgp = require("pg-promise")();

app.engine("html", mustacheExpress());
app.set("view engine", "html");
app.set("views", __dirname + "/views"); 
app.use("/", express.static(__dirname + "/public"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.get('/new_creature',function(req,res){
    res.render('new_creature/index');
});
app.post('/new_creature', function(req,res){
    res.end(JSON.stringify(req.body));
    console.log(req.body);
    // res.render('new_creature/index');
});

and here is my views/creatures/new_creature/index.html file:

<form method="POST" action="/new_creature">
    Species:<input type="text">
    Family:<input type="text">
    Habitat:<input type="text">
    Diet:<input type="text">
    Planet:<input type="text">
    <input type="submit" placeholder="submit">
</form>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you want bodyparser to work you need to have name attributes on your form elements that you want posted. For example:

<form method="POST" action="/new_creature">
    Species:<input name='species' type="text">
    Family:<input name='family' type="text">
    Habitat:<input name='habitat' type="text">
    Diet:<input name='diet' type="text">
    Planet:<input name='planet' type="text">
    <input type="submit" value="submit">
</form>

Also, placeholder doesn't make sense on a submit button; placeholder is the ghost text that's supposed to show in an input that hasnt' been filled.

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!