Bird
0
0

Which of the following is the correct way to configure TypeORM for a PostgreSQL database in a NestJS module?

easy📝 Syntax Q3 of 15
NestJS - Database with TypeORM
Which of the following is the correct way to configure TypeORM for a PostgreSQL database in a NestJS module?
A<pre>TypeOrmModule.forRoot({ type: 'mysql', host: 'localhost', port: 3306, username: 'user', password: 'pass', database: 'mydb', entities: [User], synchronize: true, })</pre>
B<pre>TypeOrmModule.forRoot({ type: 'postgres', host: 'localhost', port: 5432, username: 'user', password: 'pass', database: 'mydb', entities: [User], synchronize: true, })</pre>
C<pre>TypeOrmModule.forRoot({ type: 'sqlite', database: 'mydb.sqlite', entities: [User], synchronize: true, })</pre>
D<pre>TypeOrmModule.forRoot({ type: 'mongodb', url: 'mongodb://localhost:27017/mydb', entities: [User], synchronize: true, })</pre>
Step-by-Step Solution
Solution:
  1. Step 1: Identify PostgreSQL config

    PostgreSQL requires type: 'postgres' and default port 5432.
  2. Step 2: Check options

    Host, username, password, database, entities, and synchronize are correctly set in
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'user',
      password: 'pass',
      database: 'mydb',
      entities: [User],
      synchronize: true,
    })
    .
  3. Final Answer:

    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'user',
      password: 'pass',
      database: 'mydb',
      entities: [User],
      synchronize: true,
    })
    correctly configures PostgreSQL in NestJS.
  4. Quick Check:

    Postgres uses type 'postgres' and port 5432 [OK]
Quick Trick: Postgres uses type 'postgres' and port 5432 [OK]
Common Mistakes:
  • Using MySQL or SQLite config for Postgres
  • Wrong port number
  • Missing entities array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes