TypeScript
SQL Server

Learn how to add Prisma 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 the Prisma CLI, Prisma Client, and Prisma Introspection.

Prerequisites

In order to successfully complete this guide, you need:

  • an existing Node.js project with a package.json
  • Node.js installed on your machine
  • a PostgreSQL database server running and a database with at least one table
  • an existing Node.js project with a package.json
  • Node.js installed on your machine
  • a MySQL database server running and a database with at least one table

See System requirements for exact version requirements.

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, check out the Quickstart.

Set up Prisma

As a first step, navigate into it your project directory that contains the package.json file.

Next, add the Prisma CLI as a development dependency to your project:

$npm install prisma --save-dev

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

$npx prisma

Next, set up your Prisma project by creating your Prisma schema file template with the following command:

$npx prisma init

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).

Edit this page on GitHub