Below is the code I am using:
const express = require('express');
const fs = require('fs');
const app = express();
// MIDDLEWARE
app.use((req, res, next) => {
console.log('Hello from the Middleware 1');
console.log(req.body);
next();
});
app.use(express.json());
app.use((req, res, next) => {
console.log('Hello from the Middleware 2');
console.log(req.body);
next();
});
The first Middleware logs the req.body as undefined, but the 2nd Middleware logs the req.body as it is. I am new to Node.Js and I could not find the right explanation for this.