Bird
0
0

How should you correctly import TypeORM entities into a NestJS module?

easy📝 Syntax Q3 of 15
NestJS - Database with TypeORM
How should you correctly import TypeORM entities into a NestJS module?
AImport entities directly in the service constructor
BUse TypeOrmModule.forFeature([Entity]) inside the module's imports array
CDeclare entities in the providers array of the module
DUse TypeOrmModule.forRoot() inside the controller
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct import method

    Entities must be registered with TypeOrmModule.forFeature() to be injectable.
  2. Step 2: Understand module structure

    forFeature is used inside imports array of the module to provide repositories.
  3. Final Answer:

    Use TypeOrmModule.forFeature([Entity]) inside the module's imports array -> Option B
  4. Quick Check:

    Entities go in forFeature imports [OK]
Quick Trick: Use forFeature to register entities in modules [OK]
Common Mistakes:
  • Trying to inject entities directly in services
  • Adding entities to providers array
  • Calling forRoot inside controllers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes