Start from scratch

JavaScript
PostgreSQL

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

  • Node.js installed on your machine
  • a MySQL database server running

See System requirements for exact version requirements.

Make sure you have your database connection URL at hand. If you don't have a database server running and just want to explore Prisma, check out the Quickstart.

Create project setup

As a first step, 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 ts-node @types/node --save-dev

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:

tsconfig.json
1{
2 "compilerOptions": {
3 "sourceMap": true,
4 "outDir": "dist",
5 "strict": true,
6 "lib": ["esnext"],
7 "esModuleInterop": true
8 }
9}

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.

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 with the following command:

$npx prisma init

This command created a new directory called prisma which contains a file called 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