1.0.7 • Published 3 years ago

@nestjs-package-publishing/nestjs-app v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Installation

$ npm i @nestjs-package-publishing/nestjs-app

Import Module

import { Module } from '@nestjs/common';
import { ExampleModule } from '@nestjs-package-publishing/nestjs-app';
...

@Module({
  imports: [..., ExampleModule.register({ message: 'hello' })],
  ...
})
export class AppModule {}

The register() method requires the configuration properties:

PropertyDescriptionTypeExample
messagemessage to returnstringhello

Async configuration

You may want to pass your repository module options asynchronously instead of statically. In this case, use the registerAsync() method, which provides several ways to deal with async configuration.

import { Module } from '@nestjs/common';
import { ExampleModule } from '@nestjs-package-publishing/nestjs-app';
...

@Module({
  imports: [..., ExampleModule.registerAsync(
    {
      useFactory: (configService: ConfigService) => ({
        message: configService.get('MESSAGE')
      }),
      inject: [ConfigService],
    }
  )],
  ...
})
export class AppModule {}

Import provider only

import { Module } from '@nestjs/common';
import { AppService } from './app.service';
import { ExampleService, ExampleController } from '@nestjs-package-publishing/nestjs-app';

@Module({
  providers: [
    ...,
    {
      provide: 'EXAMPLE_MODULE_OPTIONS',
      useValue: { message: 'hello' },
    },
    ExampleService,
  ],
  controllers: [..., ExampleController]
  ...
})
export class AppModule {}

Use service

import { Injectable } from '@nestjs/common';
import { ExampleService } from '@nestjs-package-publishing/nestjs-app';

@Injectable()
export class AppService {

  constructor(private readonly exampleService: ExampleService){}

  example(): string {
    return this.exampleService.greeting();
  }
  ...
}

License

Nest is MIT licensed.