npm.io
1.0.7 • Published 5 years ago

@nestjs-package-publishing/nestjs-app

Licence
MIT
Version
1.0.7
Deps
6
Size
14 kB
Vulns
3
Weekly
0

nestjs-package-publishing

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:

Property Description Type Example
message message to return string hello

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.