My request.body is returning an empty object in express 4.17.1.
It works fine on postman, but when I try consuming it at the frontend using javascript I get an empty object, even when I console.log it
Below is my code:
/////Express backend
const express = require('express');
const cors = require('cors');
const app = express();
app.use(express.json());
app.use(cors());
////React frontend
const myData = {
_id: "616a4663c3086a539a8c3dcc",
type: "describe_yourself",
name: "white"
}
React.useEffect( () => {
fetch('http://localhost:9000/test', {
method: 'POST',
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(myData)
}).then(response => response.json())
.then(data => console.log(data))
}, [])
I am not using body-parser because it is deprecated.
I will really appreciate anyone that can help me. thanks in advance