my body is not being posted in my fetch

im following this tutorial
https://youtu.be/aD1c_YmHsFg?list=PLChiukrA-RMOEB1PRQqB1NITIRsDz9pIN&t=1745

here is my api index.js
const express = require("express");
const cors = require("cors");
const app = express();

app.use(cors());
app.get("/api/test", (req, res) => {
  res.json("test ok3");
});

app.post("/api/transaction", (req, res) => {
  res.json(req.body);
});

app.listen(4040);

here is my app.js fetch
const [name, setName] = useState("");
  const [datetime, setDatetime] = useState("");
  const [description, setDescription] = useState("");
  function addNewTransaction(ev) {
    ev.preventDefault();
    const url = process.env.REACT_APP_API_URL + "/transaction";
    fetch(url, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ name, description, datetime }),
    }).then((response) => {
      console.log(response);
      // response.json().then((json) => {
      //   console.log("result", json);
      // });
    });
  }


here is the console logged response
image.png
YouTubeCoding With Dawid
In this video, I'll be teaching you how to build a MERN Money Tracker App (Mongo db, express.js, react.js node.js). This simple app will help you track your spending, save money and gain financial insight.

If you're wanting to learn how to build an app, or just want to start tracking your money more effectively, then this is the video for you! ...
Build a MERN Money Tracker App | Simple mern app tutorial for begin...
Was this page helpful?