nestjs-general-interceptor
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

nestjs-general-interceptor

This is a simple copy from NestJS document and StackOverflow answer.

but it works out of the box.

This package is a Nest.js interceptor, it makes your controllers response to this general format:

{
  "statusCode": 200,
  "message": "ok",
  "data": "<Your orgin return data>"
}

If your controller thrown an Exception, it does nothing like the documented base example.

Installation

You can install the package from npm registry. Installation is done using command npm install :

$ npm install nestjs-general-interceptor

Usage

Within your Nest.js main.ts, import and use this module like the example below:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { TransformInterceptor } from 'nestjs-general-interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  
  // This is for global, which wrappers all your controllers
  app.useGlobalInterceptors(new TransforInterceptor());
  
  await app.listen(3000);
}

bootstrap();

Readme

Keywords

Package Sidebar

Install

npm i nestjs-general-interceptor

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

79.3 kB

Total Files

11

Last publish

Collaborators

  • remi_crystal