Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save r37r0m0d3l/d9987f63ea4c8e3e71911408874cb35d to your computer and use it in GitHub Desktop.
Save r37r0m0d3l/d9987f63ea4c8e3e71911408874cb35d to your computer and use it in GitHub Desktop.
Simplest Morgan NestJS Middleware
import { Injectable, MiddlewareFunction, NestMiddleware } from '@nestjs/common';
import * as morgan from 'morgan';
import { LoggerService } from './mylogger';
@Injectable()
export class MorganMiddleware implements NestMiddleware {
constructor(private readonly logger: LoggerService) {}
resolve(): MiddlewareFunction {
return morgan('combined', {
stream: { write: str => this.logger.info(str) },
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment