0
0
NestJSframework~10 mins

Global 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 make the module global using the decorator.

NestJS
import { Module, [1] } from '@nestjs/common';

@[1]()
@Module()
export class AppModule {}
Drag options to blanks, or click blank then click option'
AGlobal
BInjectable
CController
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Injectable instead of @Global
Forgetting to add the decorator
Confusing @Controller with @Global
2fill in blank
medium

Complete the code to export the service from the global module.

NestJS
import { Module, Global } from '@nestjs/common';
import { MyService } from './my.service';

@Global()
@Module({
  providers: [MyService],
  [1]: [MyService],
})
export class MyGlobalModule {}
Drag options to blanks, or click blank then click option'
Acomponents
Bimports
Ccontrollers
Dexports
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'imports' instead of 'exports'
Leaving out the exports array
Adding the service to controllers
3fill in blank
hard

Fix the error in the code to properly use the global module.

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

@Global()
@Module({
  providers: [ConfigService],
  exports: [[1]],
})
export class ConfigModule {}
Drag options to blanks, or click blank then click option'
AConfigController
BConfigModule
CConfigService
DConfigProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting the module class instead of the provider
Using a controller name in exports
Leaving exports empty
4fill in blank
hard

Fill both blanks to create a global module that exports a service and imports another module.

NestJS
import { Module, [1] } from '@nestjs/common';
import { SharedModule } from './shared.module';
import { LoggerService } from './logger.service';

@[1]()
@Module({
  imports: [[2]],
  providers: [LoggerService],
  exports: [LoggerService],
})
export class LoggerModule {}
Drag options to blanks, or click blank then click option'
AGlobal
BInjectable
CSharedModule
DLoggerService
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Injectable instead of @Global
Importing the service instead of the module
Forgetting to export the service
5fill in blank
hard

Fill all three blanks to define a global module that imports another module, provides a service, and exports it.

NestJS
import { Module, [1] } from '@nestjs/common';
import { DatabaseModule } from './database.module';
import { AuthService } from './auth.service';

@[1]()
@Module({
  imports: [[2]],
  providers: [[3]],
  exports: [[3]],
})
export class AuthModule {}
Drag options to blanks, or click blank then click option'
AGlobal
BDatabaseModule
CAuthService
DConfigModule
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up service and module names
Not exporting the provided service
Using wrong decorator names