Skip to content

Latest commit

 

History

History

turborepo-prisma-tasks-trigger

Turborepo monorepo demo with a Prisma package and Trigger.dev installed in a Next.js app

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.

Overview & features

  • 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 the web app.

Relevant files and code

Database package (@repo/db)

Next.js app (apps/web)

Setup and development

  1. After cloning the repository, install the dependencies in the root of the monorepo:

    pnpm install
  2. Create .env files in apps/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.

  3. Set up the database and run migrations:

    pnpm turbo db:generate   # Generate Prisma client
    pnpm turbo db:migrate    # Run migrations
  4. Update the Trigger.dev project ref in the trigger.config.ts file.

  5. 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 the packages/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.

  6. 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

  7. Go to the Trigger.dev dashboard to see the task being executed

Learn more