express logging middleware in typescript

Here's an example of how to create a logging middleware in TypeScript for an Express application:

index.ts
import { Request, Response, NextFunction } from 'express';

const loggerMiddleware = (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  console.log(`${req.method} ${req.path}`);
  next();
};

export default loggerMiddleware;
239 chars
13 lines

This middleware function logs the HTTP method and path of each request and then calls the next function to pass control to the next middleware in the chain. You can add this middleware to your Express app by calling app.use(loggerMiddleware).

gistlibby LogSnag