This example app showcases how to use the Prisma Nuxt module.
The app demonstrates:
- How to use the
usePrismaClientcomposable in a server-side component namedFirstUser.server.vue. - How to customize the
PrismaClientin the file lib/prisma.ts, which is generated by the@prisma/nuxtmodule. This customization adds anexistsmethod to thePrismaClientinstance. The extended instance of thePrismaClientwith theexistsmethod is then used in the API route located at theuser-exists.tsfile.
-
Download example and install dependencies:
npx try-prisma@latest --template orm/nuxt-prisma-module -
Navigate into the project directory:
cd nuxt-prisma-module -
Install dependencies:
npm install -
Set up your Prisma Postgres database:
npx prisma init --dbThis will prompt you to:
- Select a region (e.g.,
ap-southeast-1) - Enter a project name
- Copy the provided database URL to your
.envfile
- Select a region (e.g.,
-
Create a
.envfile with your Prisma Postgres database URL:# .env DATABASE_URL="postgres://<username>:<password>@<host>:<port>/<database>"
-
Apply database migrations:
npx prisma migrate dev -
Seed the database with sample data:
npx prisma db seed -
Start the development server:
npm run dev -
Follow the instructions in the terminal to launch Prisma Studio integrated in the Nuxt devtools within your browser.
This example uses Prisma Postgres with the @prisma/adapter-pg driver adapter configured in lib/prisma.ts:
import { PrismaPg } from '@prisma/adapter-pg'
import { PrismaClient } from '../prisma/generated/prisma/client'
const pool = new PrismaPg({ connectionString: process.env.DATABASE_URL! })
const prisma = new PrismaClient({ adapter: pool })- Check out the Prisma Nuxt module Documentation
- Check out the Prisma docs
- Join our community on Discord to share feedback and interact with other users.
- Subscribe to our YouTube channel for live demos and video tutorials.
- Follow us on X for the latest updates.
- Report issues or ask questions on GitHub.