Questions
17 of 25
1How do you define a TypeORM entity and register it in a NestJS feature module?
2How do you handle TypeORM migrations in a NestJS project?
3How do you run a transaction with Prisma in NestJS?
4How do you perform CRUD operations and add query methods to a Mongoose model in NestJS?
5How do you use Prisma with multiple databases in a single NestJS application?
6What is the difference between find(), findOne(), findOneOrFail(), and the Query Builder in TypeORM?
7What are the two main ways to run a database transaction in TypeORM with NestJS?
8How do you handle Prisma migrations in a CI/CD pipeline?
9How do you add schema middleware (hooks) and instance methods in NestJS Mongoose?
10How do you mock a repository in a NestJS unit test?
11How do you seed a database in a NestJS application?
12How do you implement a Unit of Work pattern to group database operations across repositories in NestJS?
13How do you implement optimistic locking with TypeORM to prevent lost updates in NestJS?
14How do you integrate Prisma into a NestJS application?
15How do you implement soft deletes in NestJS with TypeORM?
16How do you implement multi-tenancy with a shared database in NestJS TypeORM?
17How do you set up TypeORM in a NestJS application?
18How do you implement a custom TypeORM repository in NestJS?
19How do you propagate a TypeORM transaction across multiple services in NestJS?
20What are Prisma middleware and how do you use them for audit logging in NestJS?
21How do you set up Mongoose in a NestJS application and define a schema?
22How do you handle Mongoose transactions for multi-document atomic operations in NestJS?
23What is the repository pattern and why use it in NestJS?
24How do you handle database connection pooling and health checks in NestJS?
25How do you implement database read replicas in NestJS for read/write splitting with TypeORM?
17 / 25

How do you set up TypeORM in a NestJS application?

Difficulty: 5/10
module configuration, entity registration, database connection

Install @nestjs/typeorm and typeorm, then import TypeOrmModule.forRoot() in AppModule with your database credentials. Set synchronize to false in production and use migrations instead. Use forRootAsync with ConfigService to read credentials from environment variables.

TypeORM setup with sync and async configuration
Key configuration rules:
  1. 1

    synchronize: true auto-migrates the schema on every app start — safe in development only, destructive in production.

  2. 2

    entities glob — finds all entity files; alternatively pass entity classes directly in an array.

  3. 3

    Use forRootAsync with ConfigService to read credentials from environment variables safely.

  4. 4

    migrationsRun: true applies pending migrations on startup — use with caution in production.

  5. 5

    Register TypeOrmModule.forRoot() once in AppModule; feature modules use forFeature() to register their entities.

Scenario Questions

0-2 years experience

  1. 1You need to add a new PostgreSQL database to a NestJS project. Walk me through the steps you'd take to integrate TypeORM, including any files you’d create or modify.
  2. 2If the application fails to start after you added TypeOrmModule.forRoot, what are the first things you’d check?
  3. 3How would you define a simple User entity and make it available to a service via a repository?

2-5 years experience

  1. 1We have a feature that requires switching between a development SQLite DB and a production PostgreSQL DB without changing code. How would you configure TypeORM in NestJS to support this, and what pitfalls might you encounter?
  2. 2During a code review you notice that migrations aren’t running automatically on app start. Explain why that might happen and how you’d fix it.
  3. 3If a query using a repository is unexpectedly returning stale data after an update, what could be causing it and how would you debug it?

5-8 years experience

  1. 1Our monolith is growing and we need to split some modules into microservices, each with its own database schema. How would you structure TypeORM modules and connections in NestJS to keep them isolated yet share common entities?
  2. 2We’re seeing performance degradation on high‑traffic read endpoints that use TypeORM relations. What strategies would you employ at the NestJS/TypeORM layer to mitigate N+1 queries and improve throughput?
  3. 3Explain how you’d implement a custom repository that adds soft‑delete functionality across multiple entities, and how you’d integrate it with NestJS’s dependency injection.

8+ years experience

  1. 1The company plans to migrate from TypeORM to Prisma across several large NestJS services. Outline a migration strategy that minimizes downtime and maintains type safety, including how you’d handle existing custom repositories and shared modules.
  2. 2How would you design a shared database access library for multiple NestJS teams that abstracts TypeORM configuration, supports multiple DB vendors, and enforces consistent naming and migration policies?
  3. 3Discuss the long‑term maintenance implications of using TypeORM’s Active Record vs Data Mapper patterns in a large codebase, and which would you recommend for a platform that expects frequent schema changes.

Follow-up Questions

  • How would you load connection options from environment variables at runtime?
  • What strategy would you use to test this database integration in CI?
  • How do you keep your entities and database schema in sync over time?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.