Complete the code to make the module global using the decorator.
import { Module, [1] } from '@nestjs/common'; @[1]() @Module() export class AppModule {}
The @Global() decorator marks a module as global, so it doesn't need to be imported everywhere.
Complete the code to export the service from the global module.
import { Module, Global } from '@nestjs/common'; import { MyService } from './my.service'; @Global() @Module({ providers: [MyService], [1]: [MyService], }) export class MyGlobalModule {}
The exports array makes the service available throughout the application since the module is global.
Fix the error in the code to properly use the global module.
import { Module, Global } from '@nestjs/common'; import { ConfigService } from './config.service'; @Global() @Module({ providers: [ConfigService], exports: [[1]], }) export class ConfigModule {}
The exports array must list the provider to share it. Here, ConfigService is the provider to export.
Fill both blanks to create a global module that exports a service and imports another module.
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 {}
The @Global() decorator marks the module global, and SharedModule is imported to use its exports.
Fill all three blanks to define a global module that imports another module, provides a service, and exports it.
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 {}
The @Global() decorator makes the module global, DatabaseModule is imported, and AuthService is provided and exported.