For example, to get the body of this request:
const axios = require('axios')
axios.post('https://whatever.com/todos', {
todo: 'Buy the milk'
})
Using body-parser on Express
const express = require('express')
const app = express()
const port = 3000
const bodyParser = require('body-parser')
app.use(
bodyParser.urlencoded({
extended: true
})
)
app.use(bodyParser.json())
app.post('/', (req, res) => {
console.log(req.body)
res.send('Hello World!')
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Using express.json()
const express = require('express')
const app = express()
const port = 3000
app.use(express.json());
app.post('/', (req, res) => {
console.log(req.body)
res.send('Hello World!')
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))