Learn how to create a new Node.js or TypeScript project from scratch by connecting Prisma to your database and generating a Prisma Client for database access. The following tutorial introduces you to the Prisma CLI, Prisma Client, and Prisma Migrate.
In order to successfully complete this guide, you need:
This tutorial will also assume that you can push to the
main branch of your database. Do not do this if your
main branch has been promoted to production.
See System requirements for exact version requirements.
As a first step, create a project directory and navigate into it:
Next, initialize a TypeScript project and add the Prisma CLI as a development dependency to it:
This creates a
package.json with an initial setup for your TypeScript app.
Next, create a
tsconfig.json file and add the following configuration to it:
Next, initialize a Node.js project and add the Prisma CLI as a development dependency to it:
This creates a
package.json with an initial setup for a Node.js app.
You can now invoke the Prisma CLI by prefixing it with
Next, set up your Prisma project by creating your Prisma schema file with the following command:
This command created a new directory called
prisma which contains a file named
schema.prisma and a
.env file in the root of the project.
schema.prisma contains the Prisma schema with your database connection and the Prisma Client generator.
.env is a dotenv file for defining environment variables (used for your database connection).