req.body not populating with form data

The following files are my attempt at submitting a POST request to my nodejs (express) server. The req.body does not populate any sort of data from my form. I have done many searches and found that many of the solutions out there for this particular problem include moving bodyparser before my routes and making sure to include a name in the form fields.
Any help is appreciated.


app.use(bodyParser.urlencoded({ extended: true }));
app.use(validator({errorFormatter: -----}));
[other middleware]
require('./passport')(app, passport);
require('./routes')(app, passport);
[start server]


block content
h1= title
p Please register below
        if errors
            each error, i in errors
                li.alert.alert-danger #{error.msg}
form(method='post', action='/signup', enctype='multipart/form-data')
        label Name
        input.form-control(type='text', name='name', placeholder='Enter name')
        label Email
        input.form-control(type='email', name='email', placeholder='Enter email')
        label Username
        input.form-control(type='text', name='username', placeholder='Enter a username')
        label Password
        input.form-control(type='password', name='password')
        label Confirm Password
        input.form-control(type='password', name='passwordConfirm')
    input.btn.btn-primary.pull-right(type='submit', name='submit', value='Sign Up')

index.js (called from an'/signup', ...)

var name =,
    email =,
    username = req.body.username,
    password = req.body.password,
    passwordConfirm = req.body.passwordConfirm;

name = 'meg';

console.log('name: ' +;
console.log('email: ' +;
console.log('name2: ' + name);


name: undefined
email: undefined
name2: meg
 { host: '',
 connection: 'keep-alive',
  'content-length': '623',
  'cache-control': 'max-age=0',
   accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  origin: '',
  'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36      (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36 OPR/29.0.1795.60',
   'content-type': 'multipart/form-data; boundary=----     WebKitFormBoundaryYJyUQjMbfAn9Cr64',
  dnt: '1',
  referer: '',
  'accept-encoding': 'gzip, deflate, lzma',
  'accept-language': 'en-US,en;q=0.8',
  cookie: 'connect.sid=s%3Au9o1F_i22gHj0ZCqpHQiKWDLBGOVU1MJ.6DdtQAqbR6sriI8zF3AjQy6y1TDMD93TMGI7fRIJ5mM' }



You're using the wrong enctype for the form, express by default does not support multipart ( which is used for file uploads ), you need to use x-www-form-urlencoded.

form(method='post', action='/signup', enctype='application/x-www-form-urlencoded')

You're sending a multipart/form-data request but you're not using a multipart/form-data-compatible body parsing middleware. Some example middleware modules that do handle that format are multer and multiparty/formidable.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.