Skip to main content

Relational databases

Learn how to create a new Node.js or TypeScript project from scratch by connecting Prisma ORM 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.

Prerequisites

In order to successfully complete this guide, you need:

warning

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.

Next, initialize a Node.js project and add the Prisma CLI as a development dependency to it:

npm init -y
npm install prisma --save-dev

This creates a package.json with an initial setup for a Node.js app.

info

See installation instructions to learn how to install Prisma using a different package manager.

You can now invoke the Prisma CLI by prefixing it with npx:

npx prisma

Next, set up your Prisma ORM project by creating your Prisma Schema file with the following command:

npx prisma init

This command does two things:

  • creates a new directory called prisma that contains a file called schema.prisma, which contains the Prisma Schema with your database connection variable and schema models
  • creates the .env file in the root directory of the project, which is used for defining environment variables (such as your database connection)