Express js body parser not working? Express js body parser not working? express express

Express js body parser not working?


http://expressjs.com/guide.html#configuration

Note the use of app.router, which can (optionally) be used to mount the application routes, otherwise the first call to app.get(), app.post(), etc will mount the routes.

What's happening is you're calling app.all() before adding any of the other middleware. Doing this effectively puts app.router in front of all of your other middleware, resulting in them never being used on requests that end inside your routes.

Mounting the application routes is pretty much the same as doing app.use(app.router);.

In the end your stack is looks this:

app.use(app.router); // Contains your /test/ routeapp.use(express.bodyParser());app.use(express.cookieParser());app.use('/min',express.static('../min'));app.use('/js',express.static('../js'));app.use('/css',express.static('../css'));app.use('/img',express.static('../img'));

tl;dr Move your route between your call to app.configure() and app.listen().


I had similar problem and I figured out that this is becouse broken/missing express.bodyParser().Instead express's bodyParser i've used connect's bodyParser and it worked:

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