Tell us what’s happening:
Repl here is not processing the POST name data. I tried to console.log it and got an error, Cannot read property string of undefined
But for adding urlParser, I am using the same function I used for the GET challenge slightly earlier, which it passed.
Your code so far
var bodyParser = require('body-parser');
var urlParser = bodyParser.urlencoded({extended: false});
app.use(urlParser);
app.route('/name')
.get((req, res) => {
res.json({
name: req.query.first + ' ' + req.query.last
});
})
.post(urlParser, (req, res) => {
console.log(req.query.first)
res.json({
name: req.query.first + ' ' + req.query.last
});
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
.
Challenge: Get Data from POST Requests
Link to the challenge: