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 PrismaBuilt on unikernels, Prisma Postgres runs on bare metal servers for peak performance and infinite scalability.
The first serverless database with pay-as-you-go pricing, no infrastructure management, and zero cold starts.
Add a cache strategy to any database query and its results will be cached close to your users for peak performance and UX.
Prisma ORM is the pioneer of type-safe ORMs. Paired with NestJS, it enables high productivity and confidence through strong typing.
Prisma's service-based design fits naturally into NestJS's dependency injection system, making database access available throughout application modules.
Both NestJS and Prisma have vibrant communities where you find support, fun events and amazing developers.
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.tsimport { 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.tsimport { 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.tsimport { 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,});}}
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.tsimport { 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.tsimport { 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.tsimport { 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,});}}
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.
We have multiple channels where you can engage with members of our community as well as the Prisma team.
Browse the Prisma source code, send feedback, and get answers to your technical questions.
Find moreStay updated, engage with our team, and become an integral part of our vibrant online community.
Find moreStay updated, engage with our team, and become an integral part of our vibrant online community.
Find more