0
0
NestJSframework~10 mins

Why modules organize application structure in NestJS - Test Your Understanding

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

Complete the code to define a basic NestJS module.

NestJS
import { Module } from '@nestjs/common';

@Module({
  [1]: [],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
Acomponents
Broutes
Cservices
Dcontrollers
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'components' instead of 'controllers'.
Confusing 'services' with module metadata keys.
2fill in blank
medium

Complete the code to import another module inside a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { UsersModule } from './users/users.module';

@Module({
  imports: [[1]],
})
export class AppModule {}
Drag options to blanks, or click blank then click option'
AUserController
BUsersModule
CUserService
DUserEntity
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a service or controller instead of a module.
Forgetting to add the imported module to the imports array.
3fill in blank
hard

Fix the error in the module definition by completing the providers array.

NestJS
import { Module } from '@nestjs/common';
import { UsersService } from './users.service';

@Module({
  providers: [[1]],
})
export class UsersModule {}
Drag options to blanks, or click blank then click option'
AUsersController
BUsersModule
CUsersService
DUserEntity
Attempts:
3 left
💡 Hint
Common Mistakes
Adding controllers to providers array.
Adding modules or entities instead of services.
4fill in blank
hard

Fill both blanks to export a service and import a module in a NestJS module.

NestJS
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { UsersModule } from '../users/users.module';

@Module({
  imports: [[1]],
  providers: [AuthService],
  exports: [[2]],
})
export class AuthModule {}
Drag options to blanks, or click blank then click option'
AUsersModule
BAuthService
CUsersService
DAuthController
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting modules instead of services.
Importing services instead of modules.
5fill in blank
hard

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

NestJS
import { Module } from '@nestjs/common';
import { PaymentsService } from './payments.service';
import { UsersModule } from '../users/users.module';

@Module({
  imports: [[1]],
  providers: [[2]],
  exports: [[3]],
})
export class PaymentsModule {}
Drag options to blanks, or click blank then click option'
AUsersModule
BPaymentsService
DUsersService
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing services and modules in imports or exports.
Not exporting the service to make it available elsewhere.