import express from "express";
const app = express();
import dotenv from "dotenv";
import path from "path";
let _dirname = path.resolve();
import cors from "cors"
import { router } from "./routes.js";
import connectDB from "./src/helper/dbConnection.js";
dotenv.config();
const PORT = process.env.PORT;
app.use(cors)
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(_dirname, "public")));
router(app);
connectDB();
app.listen(PORT, () => {
console.log("Server listening on PORT:", PORT);
});
**
I am getting error like
TypeError: Cannot destructure property ‘name’ of ‘req.body’ as it is undefined.
I tried a fix for it
instead of writing it like
const { name } = req.body;
I replaced it with this
const { name } = req.body ||{};
it resolves the issue but i need the solution from the app.use(express.json()) itself
What is the replacement for app.use(express.json()) in the latest version ? Do they have any ?

