NestJS TypeORM

Official TypeORM integration module for NestJS applications

Library
npm
v11.0.3
2,146stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
89/100Excellent
Development Activity100
Maintenance84
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture80
Code Quality82
Innovation62
Learning Curve78

@nestjs/typeorm is the official NestJS wrapper around TypeORM, wiring TypeORM’s DataSource and repository pattern into Nest’s dependency-injection container. Instead of manually instantiating a data source and repositories, applications register connections declaratively through TypeOrmModule.forRoot()/forRootAsync() and inject entity repositories into providers with the @InjectRepository() decorator.

The module supports multiple named data sources in a single application, async configuration (for pulling connection options from a ConfigService or secrets manager), and custom repository classes, while staying a thin adapter over TypeORM itself rather than reimplementing any of its query or migration behavior.

What You Get

  • TypeOrmModule.forRoot() / forRootAsync() for synchronous or async (factory-based) data source configuration
  • TypeOrmModule.forFeature() to register entities per-feature-module and inject their repositories
  • @InjectRepository() and @InjectDataSource() decorators for constructor-based injection into services
  • Support for multiple named data sources within a single application
  • Custom repository support via TypeORM’s Repository extension pattern
  • An E2E test suite exercising real Postgres/MySQL connections via docker-compose, documenting supported behavior

Common Use Cases

  • Standard Nest REST/GraphQL APIs that need a relational database layer wired through DI
  • Multi-tenant or multi-database Nest applications registering several named data sources
  • Apps that load DB credentials from a ConfigService or secrets manager via forRootAsync
  • Modular Nest codebases where each feature module registers only the entities it owns via forFeature

Under The Hood

Architecture - The module centers on TypeOrmCoreModule (lib/typeorm-core.module.ts), a dynamic module created once via forRoot/forRootAsync that owns the DataSource instance and exposes it as a provider; TypeOrmModule.forFeature() (lib/typeorm.module.ts) then generates per-entity repository providers via createTypeOrmProviders (lib/typeorm.providers.ts) and registers them against a named data source tracked in data-source-name.registry.ts. EntitiesMetadataStorage (lib/entities-metadata.storage.ts) tracks which entities belong to which data source, enabling the multi-connection support, while dedicated exception classes (circular-dependency.exception.ts, duplicate-data-source.exception.ts) give descriptive errors for common misconfigurations rather than opaque DI failures.

Tech Stack - Pure TypeScript targeting the NestJS 11.x provider/module APIs (@nestjs/common, @nestjs/core as peer/dev dependencies) and TypeORM as the underlying ORM; builds via tsc, lints with oxlint, and formats with Prettier. Tests run on Vitest sequentially against real Postgres and MySQL instances spun up through the repo’s docker-compose.yml, and releases are cut with release-it behind Husky/commitlint-enforced Angular-style commit messages.

Code Quality - Nine e2e spec files under tests/e2e exercise real database round-trips (entity registration, repository injection, multiple data sources) rather than mocking TypeORM, which is a stronger quality signal for an integration layer than unit tests alone would be. The lib/ modules are small and single-responsibility (constants, providers, storage, exceptions each isolated), and public APIs are annotated with @publicApi JSDoc tags for documentation tooling.

API Design - The decorator-based API (@InjectRepository(), @InjectDataSource()) mirrors idiomatic Nest DI so existing Nest developers need no new mental model, and forRootAsync supports the standard Nest async-provider shape (useFactory/inject) for config-driven setups. The surface area is intentionally minimal — three static module methods plus two decorators — keeping boilerplate low for a data-access integration.

Used by 6 apps in this directory

TypeScript
72%
AGPL 3.0

APITable

Low Code Platforms · Databases

15,526

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
53
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated 9 months ago
TypeScript
98%
Other

Hexabot

AI Development · Automation

1,186

Build and run agentic workflows across channels with YAML, tools, and RAG

View details
79
Repo Health
76
Technical
70
Dependency
Built with
TypeScript98%
Updated yesterday
TypeScript
94%
AGPL 3.0

Laudspeaker

Marketing · Automation

2,618

Open-source customer engagement platform for building visual, event-triggered messaging journeys across email, SMS, push, in-app, and webhooks.

View details
53
Repo Health
66
Technical
64
Dependency
Built with
TypeScript94%
Updated 1 months ago
TypeScript
97%
AGPL 3.0

Swetrix

Analytics

1,123

Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.

View details
87
Repo Health
71
Technical
71
Dependency
Built with
TypeScript97%
Updated yesterday
JavaScript
59%
AGPL 3.0

ToolJet

Low Code Platforms · No Code Platforms · AI Agents

40,458

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
65
Dependency
Built with
JavaScript59%
TypeScript33%
Updated today
TypeScript
79%
Other

twenty

CRM

55,120

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
67
Dependency
Built with
TypeScript79%
MDX17%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search