2.0.2 • Published 8 months ago

@mridang/nestjs-defaults v2.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

A set of opinionated defaults for the the NestJS framework.

!NOTE This plugin has only been is designed for use with the Express tranport. It also assumes that you are using Sentry and deploying this to AWS.

Here are some of the notable features of this library:

Installation

Install using NPM by using the following command

npm install --save-dev @mridang/nestjs-defaults

Usage

Wiring this library comprises of two parts - configuring the NestJS application and configuring the Express transport.

To correctly leverage this library, you must use both.

Importing the exported module

The library exposes a module that should be imported in the root module. Importing that module will configure all the necessary defaults. The module requires that you specify the name of an AWS Secrets Manager configuration.

import { Global, Module } from '@nestjs/common';
import { DefaultsModule } from '@mridang/nestjs-defaults';

@Global()
@Module({
  imports: [
    DefaultsModule.register({
      configName: 'shush',
    }),
  ],
})
export class AppModule {
  //
}

Configuring the NestJS application

The library also provides a configure convenience method that can be used for setting up the transport e.g. the Handlebars templating engine, support for parsing cookies, validation, etc.

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ClsService } from 'nestjs-cls';
import { AsyncLocalStorage } from 'node:async_hooks';
import compression from 'compression';
import { BetterLogger, configure } from '@mridang/nestjs-defaults';

async function bootstrap() {
  const nestApp = await NestFactory.create<NestExpressApplication>(AppModule, {
    rawBody: true,
    logger: new BetterLogger(new ClsService(new AsyncLocalStorage())),
  });

  configure(nestApp, __dirname);
  nestApp.use(compression());
  await nestApp.init();
  await nestApp.listen(3000);
}

bootstrap();

Contributing

If you have suggestions for how this library could be improved, or want to report a bug, open an issue - I'd love all and any contributions.

License

Apache License 2.0 © 2024 Mridang Agarwalla

2.0.2

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago

1.6.0

8 months ago

1.5.1

9 months ago

1.5.0

9 months ago

1.4.1

9 months ago

1.4.0

9 months ago

1.3.0

9 months ago

1.2.2

9 months ago

1.2.0

9 months ago

1.2.1

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.0

9 months ago