Relational databases
Learn how to create a new TypeScript project with a Prisma Postgres database from scratch. This tutorial introduces you to the Prisma CLI, Prisma Client, and Prisma Migrate and covers the following workflows:
- Creating a TypeScript project on your local machine from scratch
- Creating a Prisma Postgres database
- Schema migrations and queries (via Prisma ORM)
- Connection pooling and caching (via Prisma Accelerate)
- Real-time database change events (via Prisma Pulse)
Prerequisites
To successfully complete this tutorial, you need:
- a (PDP) account
- Node.js installed on your machine (see system requirements for officially supported versions) (see system requirements for officially supported versions)
Create project setup
Create a project directory and navigate into it:
mkdir hello-prisma
cd hello-prisma
Next, initialize a TypeScript project and add the Prisma CLI as a development dependency to it:
npm init -y
npm install prisma typescript tsx @types/node --save-dev
This creates a package.json
with an initial setup for your TypeScript app.
Next, initialize TypeScript:
npx tsc --init
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 did the following:
- It created a new directory called
prisma
that contains a file calledschema.prisma
, which contains the Prisma schema with your database connection variable and schema models - It created a
.env
file in the root directory of the project, which is used for defining environment variables (such as your database connection and API keys).
In the next section, you'll learn how to connect your Prisma Postgres database to the project you just created on your file system.