🟢 Node.js Intermediate

What is TypeORM in Node.js?

Answer

TypeORM is an ORM for TypeScript and JavaScript that supports PostgreSQL, MySQL, SQLite, MongoDB, and more. It is particularly popular in TypeScript projects and with the NestJS framework. It supports two patterns: (1) Active Record: models extend BaseEntity and have CRUD methods directly — await user.save(); (2) Data Mapper: separate repository classes handle persistence — await userRepository.save(user) (more testable, recommended). Entities are defined with decorators: @Entity() class User { @PrimaryGeneratedColumn() id: number; @Column() name: string; @OneToMany(() => Post, post => post.user) posts: Post[]; }. TypeORM migrations track schema changes over time. Compared to Sequelize: better TypeScript and decorator support; compared to Prisma: TypeORM uses real TypeScript classes (Prisma generates its own types), but Prisma's query API is considered more ergonomic by many developers. TypeORM is the native ORM choice for NestJS applications.