Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mentos1386/nest-morgan

Morgan Logger for Nestjs
https://github.com/mentos1386/nest-morgan

logging morgan nest nest-module typescript

Last synced: about 1 month ago
JSON representation

Morgan Logger for Nestjs

Awesome Lists containing this project

README

        


Nest Logo

Morgan Module for Nest framework


NPM Version
Package License
NPM Downloads
Github Actions - Test

### NOT MAINTAINED!

Hey all. **This project is not maintained and archived.** You should check out [iamolegga/nestjs-pino](https://github.com/iamolegga/nestjs-pino) which is maintained
and with a bunch of cool features.

## Description

This's a [Morgan](https://github.com/expressjs/morgan) module for [Nest](https://github.com/nestjs/nest).

## Installation

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

### Versions

- **2.x** Is for Nest v7.x
- Remove the need to use `MorganModule.forRoot()` [#17](https://github.com/mentos1386/nest-morgan/issues/17).
- **1.x** Is for Nest v6.x
- **0.x** Is for Nest v5.x

## Quick Start

### Include Module

> app.module.ts

```ts
@Module({
imports: [MorganModule],
})
export class ApplicationModule {}
```

#### Global

If you want to set up interceptor as global, you have to follow Nest
instructions [here](https://docs.nestjs.com/interceptors). Something like
this:

> app.module.ts

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

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

### Using Interceptor

> app.controller.ts

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