Bird
0
0

What happens if you forget to add TypeOrmModule.forFeature([Entity]) in a NestJS service module?

medium📝 component behavior Q5 of 15
NestJS - Database with TypeORM
What happens if you forget to add TypeOrmModule.forFeature([Entity]) in a NestJS service module?
AThe database connection will fail to initialize
BThe application will crash on startup
CThe service cannot inject the repository for that entity
DThe entity will be automatically registered anyway
Step-by-Step Solution
Solution:
  1. Step 1: Understand forFeature purpose

    forFeature registers repositories for entities to be injected in services.
  2. Step 2: Consequence of missing forFeature

    Without it, repository injection fails, so service can't access DB for that entity.
  3. Final Answer:

    The service cannot inject the repository for that entity -> Option C
  4. Quick Check:

    Missing forFeature = no repository injection = B [OK]
Quick Trick: Use forFeature to inject repositories for entities [OK]
Common Mistakes:
  • Thinking DB connection fails without forFeature
  • Assuming app crashes on missing forFeature
  • Believing entities auto-register without forFeature

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes