/nest-morgan

Morgan Logger for Nestjs

Primary LanguageTypeScriptMIT LicenseMIT

Nest Logo

Morgan Module for Nest framework

NPM Version Package License NPM Downloads Travis build Coveralls

Description

This's a Morgan module for Nest.

Installation

$ npm i --save nest-morgan morgan @types/morgan

Versions

  • 1.x Is for Nest v6.x
  • 0.x Is for Nest v5.x

Quick Start

Include Module

app.module.ts

@Module({
    imports: [
        ...
        MorganModule.forRoot(),
    ]
})
export class ApplicationModule {}

Global

If you want to set up interceptor as global, you have to follow Nest instructions here. Something like this:

app.module.ts

import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { MorganModule, MorganInterceptor } from 'nest-morgan';

@Module({
  imports: [
      MorganModule.forRoot(),
  ],
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: MorganInterceptor('combined'),
    },
  ],
})
export class ApplicationModule {}

Using Interceptor

app.controller.ts

  @UseInterceptors(MorganInterceptor('combined'))
  @Get('/some/route')
  public async someRoute() {
    ...
  }