JSPM

nestjs-extractor

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 53
  • Score
    100M100P100Q75927F
  • License MIT

NestJS module for extract providers from parent non-global modules

Package Exports

  • nestjs-extractor
  • nestjs-extractor/.build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nestjs-extractor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Description

NestJS module for extract providers from parent non-global modules

Installation

npm install --save nestjs-extractor

Usage

Create ZooConfigService and ZooConfigModule

@Injectable()
class ZooConfigService {
    public get zooName(): string {
        return process.env.ZOO_NAME ?? 'Central Park Zoo';
    }
}

@Module({
    providers: [ZooConfigService],
    exports: [ZooConfigService],
})
class ZooConfigModule {}

Provide ZooConfigService through ExtractorModule in CatModule...

import { ExtractorModule } from 'nestjs-extractor';

@Module({
    imports: [ExtractorModule.forFeature([ZooConfigService])],
    providers: [CatService],
    controllers: [CatController],
})
class CatModule {}

...and use ZooConfigService in CatController...

@Controller()
class CatController {
    public constructor() {
        private readonly catService: CatService,
        private readonly zooConfigService: ZooConfigService,
    }

    @Get('/cat/:catId/info')
    public getCatInfo(
        @Param('catId', ParseIntPipe) catId: number,
    ): string {
        const catName = this.catService.getCatById(catId);
        const zooName = this.zooConfigService.zooName;

        return `Cat ${catName} from ${zooName}`;
    }
}

Import CatModule in ZooModule

@Module({
    imports: [CatModule, DogModule],
})
class ZooModule {}

Import ZooConfigModule and ZooModule in AppModule

@Module({
    imports: [ZooConfigModule, ZooModule],
})
class AppModule {}

License

MIT