Sobes.tech
Junior — Middle

What library or tool for working with databases is used in your NestJS project?

sobes.tech AI

Answer from AI

In NestJS projects, ORM libraries are often used for database interaction, which integrate with the framework and simplify database operations.

The most popular options are:

  • TypeORM — an officially supported ORM for TypeScript, well integrated with NestJS, supporting many databases (PostgreSQL, MySQL, SQLite, etc.).
  • Prisma — a modern ORM with a user-friendly type generator and migrations, gaining popularity in the NestJS community.
  • Sequelize — another popular ORM for Node.js, supporting SQL databases.

The choice depends on the project requirements, but most often, NestJS applications use TypeORM due to its official support and ease of integration.

Example of connecting TypeORM in NestJS:

import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: 'localhost',
      port: 5432,
      username: 'user',
      password: 'password',
      database: 'mydb',
      entities: [__dirname + '/**/*.entity{.ts,.js}'],
      synchronize: true,
    }),
  ],
})
export class AppModule {}

Thus, TypeORM is the standard tool for working with databases in NestJS projects.