request.body undefined after using express bodyParser

Edit: i fixed it by using:

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

Original post:

I'm trying to figure out how to handle a post with node and express and i'm completely stuck.

After some reading i noticed people saying i should use 'middleware' whatever that means and create a line app.use(express.bodyParser());. I assumed that after adding that i would have a req.body available in my post method. This isn't the case however. It console.log's into a undefined.

I think I don't know how to properly set this up, so here goes nothing:

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path')
  , UserProvider = require('./userprovider').UserProvider,
  qs = require('querystring');

var userProvider = new UserProvider('localhost', 27017);

var app = express(), 
    server = require('http').createServer(app),
    io = require('socket.io').listen(server);

server.listen(8080);

app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

app.get('/new_game', function (req, res) {
    res.sendfile(__dirname + '/new_game.html');
});


app.post('/new_game', function(req, res) {
    var codeToUse = Math.random()*10000;
    codeToUse = Math.round(codeToUse);
    console.log(req.body);
});


app.use(express.bodyParser());



app.listen(3000);

Though you've said now your code works, but i won't suggest you to use bodyParser in the options of

app.configure()

What it does is that, if you use it as you have done, any file can be send into your system for all post requests. It's better if you use

express.json()

and

express.urlencoded()

in the options of app.configure(), and when you expect a file use bodyParser in the respective post route like this

app.post('/upload', express.bodyParser(), function(req, res){//do something with req.files})