🦅 NestJS Intermediate

What is the @Global() decorator in NestJS?

Answer

The @Global() decorator makes a module globally available — its exported providers can be used anywhere without importing the module. Apply it to the module class: @Global() @Module({ providers: [ConfigService], exports: [ConfigService] }) class ConfigModule {}. Once ConfigModule is imported once (usually in AppModule), ConfigService is available for injection in any other module without re-importing. Use sparingly — global modules make dependencies implicit and can make code harder to understand. Appropriate use cases: configuration, logging, database connections, and utilities that are needed universally. Prefer explicit imports for most modules to make dependencies clear and testable.