Prisma
A modern, type-safe ORM for PostgreSQL, MySQL, SQLite, and MongoDB. Prisma gives you auto-generated types and a clean query API.
Prisma is a TypeScript-first ORM that turns your database schema into fully-typed query methods. StackKit sets it up with the right configuration for your chosen database provider.
Compatible frameworks
Prisma is currently available for Express projects.
Installation
In a new project
Choose your database provider with the --database flag:
npx stackkit@latest create my-app --database prisma-postgresqlnpx stackkit@latest create my-app --database prisma-mysqlnpx stackkit@latest create my-app --database prisma-sqlitenpx stackkit@latest create my-app --database prisma-mongodbIn an existing project
npx stackkit@latest add
# Navigate to: Database → Prisma → (select your provider)What gets generated
prisma/schema.prisma— Your database schema. Theprovideris pre-configured for your chosen database.src/lib/db.ts— A singleton Prisma Client instance ready to import anywhere in your app..env.example— ADATABASE_URLentry with the correct format for your provider.
Setup
Copy your environment file
cp .env.example .envSet your database URL
Open .env and update DATABASE_URL with your actual connection details:
DATABASE_URL="postgresql://user:password@localhost:5432/mydb"DATABASE_URL="mysql://user:password@localhost:3306/mydb"DATABASE_URL="file:./dev.db"SQLite stores data in a local file. No database server needed.
DATABASE_URL="mongodb://localhost:27017/mydb"
# MongoDB Atlas:
DATABASE_URL="mongodb+srv://user:[email protected]/mydb"Run your first migration
For PostgreSQL, MySQL, and SQLite, create and apply the initial migration:
npx prisma migrate dev --name initFor MongoDB, push your schema directly (Prisma doesn't use migrations with MongoDB):
npx prisma db pushGenerate Prisma Client
This step is automatic after migrations, but you can run it manually if needed:
npx prisma generateStart the development server
npm run devCommon commands
npx prisma migrate dev # Create and apply a new migration
npx prisma migrate dev --name init # Create with a specific name
npx prisma generate # Regenerate the Prisma Client
npx prisma studio # Open the visual database browser
npx prisma db push # Sync schema without creating a migration
npx prisma db seed # Run your seed scriptUsing the Prisma Client
The generated src/lib/db.ts file exports a singleton Prisma Client instance. Import it wherever you need to query the database:
import { db } from "@/lib/db";
// Fetch all users
const users = await db.user.findMany();
// Create a new user
const user = await db.user.create({
data: {
name: "Alice",
email: "[email protected]",
},
});The Prisma Client types are generated from your schema, so you get full autocomplete and type checking for every query.
Next steps
- Mongoose — An alternative for MongoDB-only projects
- Troubleshooting — Common setup issues