I am able to retrieve(get) data from express but cannot post data to express...
client:
<html>
<button onclick="myFunction()">send</button>
<script>
const data = {"experience" : 0};
function myFunction(){
fetch("/post", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
}
</script>
</html>
express:
Here I was getting undefined, but when I added express.json(), I got "{}". The client's and the server's conections are good, but there is no body where the data is stored? I made sure my client code was working fine by posting data to webhooks.site, it worked fine. I think there is some kind of rookie mistake... Btw, I am using react and express, I just simplified my code... any suggestions will be appreciated
const express = require("express");
const app = express();
app.post("/post", express.json() ,function (req,res){
console.log(req.body)
})
const port = 5000;
app.listen(port, () => `Server running on port ${port}`);