https://github.com/bhandarisachindev/NodeBackend.git day-11

What is Middleware?

Middleware functions are functions that have access to the request object (req), the response object (res), and the next() function in the application’s request-response cycle.

They can:

(req, res, next) => {
  // Do something
  next();
}

🔄 Types of Middleware

  1. Application-level middleware
  2. Router-level middleware
  3. Built-in middleware (like express.json())
  4. Error-handling middleware
  5. Third-party middleware (e.g., morgan, multer)

âś… Application-level Middleware

const express = require('express');
const app = express();

app.use((req, res, next) => {
  console.log('Time:', Date.now());
  next();
});