typeorm
TypeORM is a full-featured ORM for TypeScript and JavaScript that supports both Active Record and Data Mapper patterns, working with PostgreSQL, MySQL, MariaDB,…
Installation
npm install typeorm
yarn add typeorm
pnpm add typeorm
Import
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';Quick Example
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column({ unique: true })
email: string;
}About typeorm
TypeORM is a full-featured ORM for TypeScript and JavaScript that supports both Active Record and Data Mapper patterns, working with PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, CockroachDB, and MongoDB. TypeORM uses decorators to define entities (database tables), columns, relations, indices, and constraints directly on TypeScript classes, providing a natural mapping between objects and database records. The library supports eager and lazy relations, cascading operations, query builders with complex joins and subqueries, transactions, migrations, subscribers for entity lifecycle events, and connection pooling. TypeORM provides both a repository pattern (EntityManager/Repository) and a query builder for flexible data access. The Active Record pattern lets entities call methods like User.find() directly, while the Data Mapper pattern separates the entity definition from the repository logic. TypeORM integrates tightly with NestJS through @nestjs/typeorm, providing dependency injection for repositories. The migration system generates SQL migrations from entity changes. While Prisma has gained ground for new TypeScript projects, TypeORM remains popular in enterprise applications, particularly those using the decorator-based NestJS pattern.
Quick Facts
| Package | typeorm |
| Category | Database |
| Weekly Downloads | 1.5M+ |
| License | MIT |
| Install | npm install typeorm |
Related Packages
Prisma is a next-generation Node.js and TypeScript ORM that provides a declarative data modeling lan…
Sequelize is a promise-based Node.js ORM that supports PostgreSQL, MySQL, MariaDB, SQLite, and Micro…
NestJS is a progressive Node.js framework for building efficient, reliable, and scalable server-side…
pg (node-postgres) is the standard PostgreSQL client for Node.js, providing low-level access to Post…
mysql2 is a high-performance MySQL client for Node.js that provides prepared statements, non-UTF-8 e…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.