Bird
0
0

What is a common mistake in this NestJS TypeORM module configuration?

medium📝 Debug Q6 of 15
NestJS - Database with TypeORM
What is a common mistake in this NestJS TypeORM module configuration?
@Module({
  imports: [TypeOrmModule.forRoot({
    type: 'postgres',
    host: 'localhost',
    port: 5432,
    username: 'user',
    password: 'pass',
    database: 'testdb',
    entities: [User],
  })],
})
export class AppModule {}
AUsing <code>entities</code> array instead of <code>entitySchemas</code>
BMissing <code>synchronize: true</code> to auto-create tables during development
CPlacing TypeOrmModule.forRoot() inside providers array
DNot importing User entity in the module file
Step-by-Step Solution
Solution:
  1. Step 1: Check configuration completeness

    Without synchronize: true, tables won't auto-create during development.
  2. Step 2: Validate other options

    Using entities is correct; forRoot must be in imports; User entity is imported.
  3. Final Answer:

    Missing synchronize: true to auto-create tables during development -> Option B
  4. Quick Check:

    Missing synchronize causes schema issues [OK]
Quick Trick: Add synchronize: true for auto schema sync in dev [OK]
Common Mistakes:
  • Confusing entities with entitySchemas
  • Placing forRoot in providers
  • Forgetting to import entity files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes