Performance: Shared modules
MEDIUM IMPACT
This affects the initial load time and memory usage by controlling how code is reused across the app.
import { CommonService } from './common.service'; import { Module } from '@nestjs/common'; @Module({ providers: [CommonService], exports: [CommonService] }) export class SharedModule {} @Module({ imports: [SharedModule], }) export class FeatureModule {} @Module({ imports: [SharedModule], }) export class AnotherFeatureModule {}
import { CommonService } from './common.service'; import { Module } from '@nestjs/common'; @Module({ providers: [CommonService], exports: [CommonService] }) export class FeatureModule {} @Module({ imports: [FeatureModule], providers: [CommonService], // duplicated provider }) export class AnotherFeatureModule {}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Duplicated providers in multiple modules | N/A | N/A | N/A | [X] Bad |
| Single shared module providing common services | N/A | N/A | N/A | [OK] Good |