NestJS TypeORM

Official TypeORM integration module for NestJS applications

Library
npm
v12.0.1
2,156 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
88 /100 Excellent
Development Activity 96
Maintenance 84
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 80
Code Quality 82
Innovation 62
Learning Curve 78

@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

Databases · Low Code Platforms

15,623

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

View details
71
Repo Health
77
Technical
60
Dependency
Built with
TypeScript 72%
Java 22%
Updated 3 weeks ago
TypeScript
98%
Other

Hexabot

AI Development · Automation

1,260

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

View details
78
Repo Health
76
Technical
65
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
TypeScript
94%
AGPL 3.0

Laudspeaker

Automation · Marketing

2,626

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

View details
51
Repo Health
66
Technical
62
Dependency
Built with
TypeScript 94%
Updated 2 months ago
TypeScript
97%
AGPL 3.0

Swetrix

Analytics

1,200

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

View details
88
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 5 days ago
JavaScript
57%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,007

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
63
Dependency
Built with
JavaScript 57%
TypeScript 36%
Updated 4 days ago
TypeScript
82%
Other

twenty

CRM

57,585

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
64
Dependency
Built with
TypeScript 82%
MDX 15%
Updated 4 days ago

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