Saturday, May 21, 2011

req.body undefined in POST request in Express js

You have to use a bodyparser to process the body of a POST request

app.use(express.bodyParser());

and put this before the routing definition, like this

app.configure('development', function() {

console.log("Development mode");

app.configure(function() {
app.use(express.bodyParser());
app.use(app.router);
.....
});
});


here is the related google groups thread.

1 comment:

  1. Thank you for this post.
    However i had to set bodyParser like that:

    app.use(require('connect').bodyParser());

    The one boudled with express didn't worked at all I had to use bodyParser from connect library.

    ReplyDelete