Bird
0
0

Given this NestJS module code, what will happen?

medium📝 component behavior Q13 of 15
NestJS - Database with TypeORM
Given this NestJS module code, what will happen?
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './user.entity';

@Module({
  imports: [TypeOrmModule.forFeature([User])],
})
export class UserModule {}
AUser entity is registered for database operations in this module
BTypeORM connection is established here
CUserModule will throw an error because forFeature is invalid
DUser entity is ignored and not available in this module
Step-by-Step Solution
Solution:
  1. Step 1: Understand what TypeOrmModule.forFeature does

    This method registers the given entities (here User) so they can be injected and used in this module's services and controllers.
  2. Step 2: Confirm that connection setup is separate

    Connection setup happens in forRoot(), not forFeature(), so no connection is established here.
  3. Final Answer:

    User entity is registered for database operations in this module -> Option A
  4. Quick Check:

    forFeature() registers entities [OK]
Quick Trick: forFeature() registers entities, forRoot() sets connection [OK]
Common Mistakes:
  • Thinking forFeature() establishes connection
  • Believing forFeature() is invalid
  • Assuming entities are ignored

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes