Node.js, Prisma & PostgreSQL

Lesson 2 of 12

Setting Up PostgreSQL and a Prisma Project

1. Get a PostgreSQL database running

Locally (via Docker) or a hosted free tier both work, either way you end up with a connection string:

postgresql://USER:PASSWORD@HOST:PORT/DATABASE

2. Create a Node project and install Prisma

npm init -y
npm install prisma --save-dev
npm install @prisma/client
npx prisma init

npx prisma init creates:

  • prisma/schema.prisma, where you'll define your data models.
  • .env, with a DATABASE_URL placeholder for your connection string.

3. Point it at your database

DATABASE_URL="postgresql://postgres:secret@localhost:5432/blog_dev?schema=public"

Prisma reads DATABASE_URL from your environment, never hardcode credentials directly in schema.prisma.

📝 Setup Quiz

Passing score: 70%
  1. 1.Which command scaffolds a new prisma/schema.prisma file and a .env template?

  2. 2.Prisma reads the database connection string from the environment variable ____.

  3. 3.Database credentials should be hardcoded directly inside schema.prisma.