Learn how to add Prisma ORM to an existing Node.js or TypeScript project by connecting it to your database and generating a Prisma Client for database access. The following tutorial introduces you to Prisma CLI, Prisma Client, and Prisma Introspection.
If you're migrating to Prisma ORM from Mongoose, see our Migrate from Mongoose guide.
In order to successfully complete this guide, you need:
installed on your machine
Access to a MongoDB 4.2+ server with a replica set deployment. We recommend using .
The MongoDB database connector uses transactions to support nested writes. Transactions requires a deployment. The easiest way to deploy a replica set is with . It's free to get started.
Make sure you have your database connection URL (that includes your authentication credentials) at hand! If you don't have a database server running and just want to explore Prisma ORM, check out the Quickstart.
See System requirements for exact version requirements.
As a first step, navigate into it your project directory that contains the
Next, add the Prisma CLI as a development dependency to your project:
You can now invoke the Prisma CLI by prefixing it with
Next, set up your Prisma ORM project by creating your Prisma schema file template with the following command:
This command does two things:
- creates a new directory called
prismathat contains a file called
schema.prisma, which contains the Prisma schema with your database connection variable and schema models
- creates the
.envfile in the root directory of the project, which is used for defining environment variables (such as your database connection)