When I send fetch request from my React app NodeJS server doesn't receive any params...
React:
fetch('http://xxx:5000/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ 'url': '[email protected]', 'password': '12345' }) // formData
})
NodeJS:
const bodyParser = require('body-parser')
const urlencodedParser = bodyParser.urlencoded({ extended: false })
const app = express()
app.post('/', urlencodedParser, async (req, resp, next) => {
const url = req.body.url
console.log(url) // undefined
const urlIdPattern = /\d+/g
}
When I send request directly from form tag it works correctly
<form action="xxx" method="POST">
<input name="url">
</form>