This example demonstrates how to use Trigger.dev and Prisma in a monorepo created with Turborepo. Prisma has been added as a package, and Trigger.dev has been installed in a Next.js app. The task is triggered by a button click in the app via a server action.
- This monorepo has been created using the Turborepo CLI, following the official Prisma and Turborepo docs, and then adapted for use with Trigger.dev.
- pnpm has been used as the package manager.
- A database package (
@repo/db
) using Prisma ORM is used to interact with the database. You can use any popular Postgres database supported by Prisma, e.g. Supabase, Neon, etc. - A Next.js example app (
apps/web
) to show how to trigger the task via a server action. - Trigger.dev initialized and an
addNewUser
task created in theweb
app.
- Located in
/packages/database/
and exported as@repo/db
- Schema defined in
/packages/database/prisma/schema.prisma
- Provides database access to other packages and apps
- Contains Trigger.dev configuration in
trigger.config.ts
- Trigger.dev tasks are defined in
src/trigger/
(e.g.,addNewUser.ts
) - Demonstrates triggering tasks via server actions in
app/api/actions.ts
-
After cloning the repository, install the dependencies in the root of the monorepo:
pnpm install
-
Create
.env
files inapps/web
,packages/database
with the correct environment variables. Copy the structure from the.env.example
files and use the correct values for your database and Trigger.dev project. If you don't have a Trigger.dev project yet, you can create one at here. -
Set up the database and run migrations:
pnpm turbo db:generate # Generate Prisma client pnpm turbo db:migrate # Run migrations
-
Update the Trigger.dev project ref in the
trigger.config.ts
file. -
Start the development server for the Next.js app:
pnpm turbo run dev --filter=web
and in a separate terminal window, run the Trigger.dev
dev
command, in thepackages/tasks
folder:cd packages/tasks pnpm dlx trigger.dev@latest dev
Note: when running the dev command, you will get some warnings in the console: "▲ WARNING The condition "default" here will never be used as it comes after both "import" and "require" package.json". These warnings can be safely ignored, and won't affect the functionality of the app. They will be fixed in an upcoming release.
-
Access the application at http://localhost:3000, and test the functionality by clicking the "Add new user" button on the web app to trigger the task
-
Go to the Trigger.dev dashboard to see the task being executed
- Trigger.dev docs - learn about Trigger.dev and its features.
- Turborepo docs - learn about Turborepo and its features.
- Prisma docs - learn about Prisma and its features.