I'm using the express.json()
before the app.patch
but both req.body & req.params.id
return undefined. I've tried to change the route to /:id
but it didn't work. It works for app.get
and app.post
.
Headers: Content-Type: application/json
const express = require("express");
const dotenv = require("dotenv")
dotenv.config({ path: ".env" });
const app = express();
app.use(express.json());
app.patch("/api/v1/", (res, req, next) => {
console.log(req.body);
});
const PORT = process.env.PORT || 5000;
app.listen(
PORT,
console.log(
`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`.yellow.bold
)
);
Any ideas? Thank you.