0
0
NestJSframework~10 mins

Shared modules in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import a shared module in a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { SharedModule } from './shared/shared.module';

@Module({
  imports: [[1]],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
ACoreModule
BSharedModule
CCommonModule
DAppModule
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong module name.
Forgetting to add the module to the imports array.
2fill in blank
medium

Complete the code to export a service from a shared module.

NestJS
import { Module } from '@nestjs/common';
import { LoggerService } from './logger.service';

@Module({
  providers: [LoggerService],
  exports: [[1]],
})
export class SharedModule {}
Drag options to blanks, or click blank then click option'
ALoggerService
BDatabaseService
CAppService
DAuthService
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting a service not provided in the module.
Forgetting to export the service.
3fill in blank
hard

Fix the error in the shared module to properly export the service.

NestJS
import { Module } from '@nestjs/common';
import { ConfigService } from './config.service';

@Module({
  providers: [ConfigService],
  exports: [[1]],
})
export class SharedModule {}
Drag options to blanks, or click blank then click option'
AConfig
BConfigModule
CSharedModule
DConfigService
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting the module instead of the service.
Using incorrect names in the exports array.
4fill in blank
hard

Fill both blanks to create a shared module that provides and exports a service.

NestJS
import { Module } from '@nestjs/common';
import { [1] } from './cache.service';

@Module({
  providers: [[2]],
  exports: [[2]],
})
export class CacheModule {}
Drag options to blanks, or click blank then click option'
ACacheService
BCacheModule
CCacheController
DCacheProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using module or controller names instead of service names.
Not exporting the service after providing it.
5fill in blank
hard

Fill the blank to import a shared module so its exported service can be used in this module.

NestJS
import { Module } from '@nestjs/common';
import { [1] } from './shared/shared.module';

@Module({
  imports: [[1]],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
ASharedModule
BLoggerService
CAppService
DCoreModule
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong module.
Listing the service in providers (unnecessary).
Directly importing the service class.