Enterprise-ready database for NestJS apps

Build high-performance and type-safe NestJS apps with Prisma’s developer-friendly database tools: The world’s most popular TypeScript ORM and the first serverless database without cold starts.

Try NestJS with Prisma

Why NestJS and Prisma?

Built for high-performance web apps

Built on unikernels, Prisma Postgres runs on bare metal servers for peak performance and infinite scalability.

Serverless, without cold starts

The first serverless database with pay-as-you-go pricing, no infrastructure management, and zero cold starts.

Built-in global caching

Add a cache strategy to any database query and its results will be cached close to your users for peak performance and UX.

TypeScript-first

Prisma ORM is the pioneer of type-safe ORMs. Paired with NestJS, it enables high productivity and confidence through strong typing.

Perfect for dependency injection

Prisma's service-based design fits naturally into NestJS's dependency injection system, making database access available throughout application modules.

Helpful communities

Both NestJS and Prisma have vibrant communities where you find support, fun events and amazing developers.

How Prisma Postgres and NestJS fit together

Prisma’s database tools are the perfect fit for building scalable and type-safe NestJS applications. Prisma integrates smoothly with the modular architecture of NestJS, no matter if you're building REST or GraphQL APIs.

Basic CRUD

Prisma Postgres integrates perfectly with NestJS's dependency injection system and modular architecture. By creating a PrismaService that extends the PrismaClient, you can inject database access throughout your application.

// src/prisma/prisma.service.ts
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
}

NestJS's controller/service pattern pairs naturally with Prisma's type-safe queries, creating a clean separation between your API endpoints and database operations. Here’s how you can implement GET and POST routes for users:

// src/users/users.controller.ts
import { Controller, Get, Post, Body } from '@nestjs/common';
import { UsersService } from './users.service';
@Controller('users')
export class UsersController {
constructor(private usersService: UsersService) {}
@Get()
findAll() {
return this.usersService.findAll();
}
@Post()
create(@Body() data: { name: string; email: string }) {
return this.usersService.create(data);
}
}

These routes will access the PrismaService as follows:

// src/users/users.service.ts
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class UsersService {
constructor(private prisma: PrismaService) {}
async findAll() {
return this.prisma.user.findMany();
}
async create(data: { name: string; email: string }) {
return this.prisma.user.create({
data,
});
}
}
Authentication Guard
Transactions
Data Model & Migrations

Prisma Postgres integrates perfectly with NestJS's dependency injection system and modular architecture. By creating a PrismaService that extends the PrismaClient, you can inject database access throughout your application.

// src/prisma/prisma.service.ts
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
}

NestJS's controller/service pattern pairs naturally with Prisma's type-safe queries, creating a clean separation between your API endpoints and database operations. Here’s how you can implement GET and POST routes for users:

// src/users/users.controller.ts
import { Controller, Get, Post, Body } from '@nestjs/common';
import { UsersService } from './users.service';
@Controller('users')
export class UsersController {
constructor(private usersService: UsersService) {}
@Get()
findAll() {
return this.usersService.findAll();
}
@Post()
create(@Body() data: { name: string; email: string }) {
return this.usersService.create(data);
}
}

These routes will access the PrismaService as follows:

// src/users/users.service.ts
import { Injectable } from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class UsersService {
constructor(private prisma: PrismaService) {}
async findAll() {
return this.prisma.user.findMany();
}
async create(data: { name: string; email: string }) {
return this.prisma.user.create({
data,
});
}
}

Featured Prisma & NestJS community examples

A starter kit covering everything you need to build NestJS with Prisma in production.

Learn how to use Prisma with NestJS in the official NestJS documentation.

This npm library helps you integrate Prisma ORM in NestJS applications. Its PrismaModule gives access to a PrismaService which you can use via dependency injection in your controller, resolver, services, guards and more.

A comprehensive tutorial series about building a NestJS REST API with Prisma.

An in-depth article about the migration process of a NestJS app from TypeORM to Prisma.

Join the Prisma Community

We have multiple channels where you can engage with members of our community as well as the Prisma team.

Discord

Chat in real-time, hang out, and share ideas with community members and our team.

Find more

GitHub

Browse the Prisma source code, send feedback, and get answers to your technical questions.

Find more

X

Stay updated, engage with our team, and become an integral part of our vibrant online community.

Find more

Youtube

Stay updated, engage with our team, and become an integral part of our vibrant online community.

Find more