Mathieu Bertin Mathieu Bertin - 10 months ago 96
Javascript Question

Sending a POST request with chai sends an empty body?

I have the following setup right now


var user = {
username: 'test_user',
email: '',
password: 'you shall not pass',
address: 'No where street'

I'm handling the post request in my routes/user.js'/', function(req, res, next) {
console.log('body: ' + req.body);
.then(function(id) {
return queries.getSingleUser(id);
.then(function(user) {
.catch(function(err) {

req.body ends up being undefined. Any clue as to what might be going wrong?

The code is live at if anybody wants to have a look.

Answer Source

req.body being undefined is generally caused by either not using the body-parser middleware in Express, or declaring it incorrectly (for instance, after the route that wants to access req.body).

Assuming that Chai sends JSON, add this to your Express app:


(before you declare the routers)