I can't seem to figure out why when I'm doing an axios.post method providing a body of data, it gets captured as undefined on my server.
I have the following files with snippets of code:
app.js:
auth(user, pass){
return axios.post('http://localhost:3000/auth', {
username: user,
password: pass
})
}
server.js:
app.post('/auth', (req, res) => {
console.log(req.body) //undefined
res.end("Success")
})
I'm how can I properly handle the POST data using axios? Am I missing something?
The success returns fine, but the username / password cannot seem to be found anywhere in the req
Add following parser to handle the requested data
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With