Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

express.js express-resource POST (create) req.body is undefined

express.js express-resource POST (create) req.body is undefined

Problem

Windows.

Node 0.8 express.js/express-resource

// Configuration of Express Application for all environments
app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(express.bodyParser());
    //app.use(require('connect').bodyParser());
    app.use(express.methodOverride());

    app.use(express.static(__dirname + '/public')); // for static assets (css)
    app.use(express.static(__dirname + '/..')); // for static assets (css)

    app.use(app.router);
});
app.resource("data", require('.....js'));

Send POST /data (in FireBug): account[foo] bar name New

in created method (req, res)

req.body is undefined.

There are some talks in the internet about a like problem (with bodyParser or Router), but I could not fix it.

A

Problem courtesy of: WHITECOLOR

Solution

Solved. Just in case for someone: I called app.get(..) before bodyParser middleware.

Solution courtesy of: WHITECOLOR

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

express.js express-resource POST (create) req.body is undefined

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×