Reputation: 348
I am trying to read form-data sent using postman. Here is the code !!
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/action', function(req, res) {
res.send('You sent the name "' + req.body.name + '".');
});
app.listen(8074);
Output: You sent the name undefined
Why is the name not being printed ? I have followed all procedures in the net but couldn't find the answer ... Where am i wrong ??
Here is screenshot tells about what i do in postman
Upvotes: 0
Views: 748
Reputation: 944442
You've ticked the "form-data" box instead of the "x-www-form-urlencoded" box in Postman, but you've used the urlencoded
body parser in your JS.
You need to match the body parser to the encoding method you use.
Upvotes: 3