0

Now that express is not shipped anymore with middleware that fills the req.body variable i am fighting to get req.body filled again. I am sending a POST request to /xyz/:object/feedback.

here my code:

app.post('/xyz/:object/feedback', function(req, res)
{
    console.log('Feedback received.');

    console.log('Body: ', req.body); // is not available :(

    res.set('Content-Type', 'text/plain; charset=utf8');
    res.send(result ? JSON.stringify(req.body) : err);
});

I tried to use body-parser already, but "Feedback received." never got logged to my console. So something seems to get stuck here:

var bodyParser = require('body-parser');
app.use(bodyParser);

How can i get req.body filled? (i need some working code)

Thariama
  • 50,002
  • 13
  • 138
  • 166

2 Answers2

4

The problem is that you pass the whole module to the use method not the required instance.

Instead of this:

app.use(bodyParser);

do

app.use(bodyParser());
0101
  • 2,697
  • 4
  • 26
  • 34
0

You need to do app.use(bodyParser()).

bodyParser() will return a function with what to use. bodyParser on its own is an invalid function for Express.

Scimonster
  • 32,893
  • 9
  • 77
  • 89