MIddlewares in Express
What is Middleware? Middleware in Express is like a security guard or helper that sits between the request (client) and the response (server) . It can modify, check, or handle requests before they reach the final destination (route handler). const express = require ( 'express' ); const app = express (); const port = 3000 const fs = require ( "fs" ) // Middleware function const logger = ( req , res , next ) => { console . log ( `we are inside middleware` ); next (); // Move to the next middleware or route handler, if next() not written, req stop here..no further execution }; // Use middleware app . use ( logger ); app . use (( req , res , next ) => { const timestamp = Date . now (); const date = new Date ( timestamp ); console . log ( date . toString ()); fs . appendFileSync ( "logs.txt" , ` ${ date . toString () } is a ${ req . method } \n ` ) ...