Bird
0
0

You wrote this code but get a runtime error:

medium📝 Debug Q6 of 15
NestJS - Database with TypeORM
You wrote this code but get a runtime error:
TypeOrmModule.forRoot({
  type: 'mysql',
  host: 'localhost',
  port: 3306,
  username: 'root',
  password: 'pass',
  database: 'test',
  entities: [User],
  synchronize: true,
})

What is the most likely cause?
AIncorrect port number for MySQL
Bsynchronize cannot be true for MySQL
CEntities array should be empty
DMissing MySQL driver package in dependencies
Step-by-Step Solution
Solution:
  1. Step 1: Check common runtime errors

    Runtime errors often occur if the database driver package is missing.

  2. Step 2: Verify MySQL driver presence

    For MySQL, mysql2 package must be installed; otherwise, connection fails.

  3. Final Answer:

    Missing MySQL driver package in dependencies -> Option D
  4. Quick Check:

    Missing DB driver package = runtime error [OK]
Quick Trick: Install mysql2 package for MySQL connection [OK]
Common Mistakes:
  • Assuming port 3306 is wrong
  • Thinking entities array must be empty
  • Believing synchronize is disallowed for MySQL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes