Complete the code to import a shared module in a NestJS module.
import { Module } from '@nestjs/common'; import { SharedModule } from './shared/shared.module'; @Module({ imports: [[1]], }) export class AppModule {}
You import the shared module by adding SharedModule to the imports array.
Complete the code to export a service from a shared module.
import { Module } from '@nestjs/common'; import { LoggerService } from './logger.service'; @Module({ providers: [LoggerService], exports: [[1]], }) export class SharedModule {}
To share a service, you export it from the shared module by adding it to the exports array.
Fix the error in the shared module to properly export the service.
import { Module } from '@nestjs/common'; import { ConfigService } from './config.service'; @Module({ providers: [ConfigService], exports: [[1]], }) export class SharedModule {}
The service to export must be the provider itself, here ConfigService.
Fill both blanks to create a shared module that provides and exports a service.
import { Module } from '@nestjs/common'; import { [1] } from './cache.service'; @Module({ providers: [[2]], exports: [[2]], }) export class CacheModule {}
You import, provide, and export the CacheService to share it.
Fill the blank to import a shared module so its exported service can be used in this module.
import { Module } from '@nestjs/common'; import { [1] } from './shared/shared.module'; @Module({ imports: [[1]], }) export class AppModule {}
providers (unnecessary).By importing the SharedModule, its exported LoggerService becomes available for injection in controllers and providers of this module.