fetch api empty body code example
Example 1: fetch api req.body empty
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
app.use(bodyParser.urlencoded())
app.use(bodyParser.json())
app.listen(2000);
app.post("/", function (req, res) {
console.log(req.body)
res.send(200, req.body);
});
Example 2: sending json data uing fetch is empty
fetch('/api/v1/users', {
method: 'post',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ "user": {
"email" : email,
"password" : password
}}),
})