Node.js and expressjs paypal ipn listener gives error 500

I have created a paypal ipn listener by using node.js and express. Here is my listener code:

exports.ipn = function(req, res, next) {
    console.log('Paypal');
    var ipn = require('paypal-ipn');
    if(typeof req.body != "undefined") {
        ipn.verify(req.body, function callback(err, msg) {
            if (err) {
                winston.error('IPN: ' + err);
            } else {
                if (req.body.payment_status == 'Completed' && msg == "VERIFIED") {
                    winston.info('IPN: ' + msg + " " + req.body.txn_id + " " + req.body.payer_email);
                }
            }
            res.send(200);
            res.end();
        });
    }
    res.send(200);
    res.end();
};

Here is my expressjs settings and routes:

    var app = express();

    // all environments
    app.set('port', process.env.PORT || 3000);
    app.use(express.logger('dev'));
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);

    // development only
    if ('development' == app.get('env')) {
      app.use(express.errorHandler());
    }

    app.get('/', routes.index);
    app.options('/', routes.options);
    app.post('/', routes.up);
    app.post('/ipn', routes.ipn);

    http.createServer(app).listen(app.get('port'), function(){
      console.log('Express server listening on port ' + app.get('port'));
    });

I use this module https://github.com/andzdroid/paypal-ipn to verify ipn messages and it works fine with the paypal ipn simulator but when I try to use it live I get this to my node console:

undefined
POST /ipn 500 351ms

There are no other error messages, just this error 500 and undefined. Can someone help me to find out what is this undefined variable and why is this error 500 happening. It happens even if I comment out everything in the listener.

Edit:

I changed the paypal ipn url to some random url which I have not defined. I still get undefined and error 500. If I post with curl I get error 404 like I should.

Edit:

I found out that if I do post using curl like this:

curl -d "test" -A "-" http://127.0.0.1/randomurl

Then I will get error 500. This gives me 404:

curl -d "test=er" -A "-" http://127.0.0.1/randomurl

I found a solution. There was something wrong in expressjs bodyParser. I changed the expressjs settings to use connect module's bodyParser like this:

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