Skip to main content
This guide covers how to manually set up Trigger.dev in your project, including configuration for different package managers, monorepos, and build extensions. This guide replicates all the steps performed by the trigger.dev init command. Follow our Quickstart for a more streamlined setup.

Prerequisites

  • Node.js 18.20+ (or Bun runtime)
  • A Trigger.dev account (sign up at trigger.dev)
  • TypeScript 5.0.4 or later (for TypeScript projects)

CLI Authentication

Before setting up your project, you need to authenticate the CLI with Trigger.dev:
This will open your browser to authenticate. Once authenticated, you’ll need to select or create a project in the Trigger.dev dashboard to get your project reference (e.g., proj_abc123).

Package installation

Install the required packages based on your package manager:

Environment variables

For local development, you need to set up the TRIGGER_SECRET_KEY environment variable. This key authenticates your application with Trigger.dev.
  1. Go to your project dashboard in Trigger.dev
  2. Navigate to the “API Keys” page
  3. Copy the DEV secret key
  4. Add it to your local environment file:

Self-hosted instances

If you’re using a self-hosted Trigger.dev instance, also set:

CLI setup

You can run the Trigger.dev CLI in two ways:

Option 1: Using npx/pnpm dlx/yarn dlx

Option 2: Add as dev dependency

Add the CLI to your package.json:
Then add scripts to your package.json:

Version pinning

Make sure to pin the version of the CLI to the same version as the SDK that you are using:
While running the CLI dev or deploy commands, the CLI will automatically detect mismatched versions and warn you.

Configuration file

Create a trigger.config.ts file in your project root (or trigger.config.mjs for JavaScript projects):

Using the Bun runtime

By default, Trigger.dev will use the Node.js runtime. If you’re using Bun, you can specify the runtime:
See our Bun runtime documentation for more information.

Add your first task

Create a trigger directory (matching the dirs in your config) and add an example task:
src/trigger/example.ts
See our Tasks docs for more information on how to create tasks.

TypeScript config

If you’re using TypeScript, add trigger.config.ts to your tsconfig.json include array:

Git config

Add .trigger to your .gitignore file to exclude Trigger.dev’s local development files:
If you don’t have a .gitignore file, create one with this content.

React hooks setup

If you’re building a React frontend application and want to display task status in real-time, install the React hooks package:

Installation

Basic usage

  1. Generate a Public Access Token in your backend:
  1. Use hooks to monitor tasks:
For more information, see the React Hooks documentation.

Build extensions

Build extensions allow you to customize the build process. Ensure you have the @trigger.dev/build package installed in your project (see package installation). Now you can use any of the built-in extensions:
See our Build extensions docs for more information on how to use build extensions and the available extensions.

Monorepo setup

There are two main approaches for setting up Trigger.dev in a monorepo:
  1. Tasks as a package: Create a separate package for your Trigger.dev tasks that can be shared across apps
  2. Tasks in apps: Install Trigger.dev directly in individual apps that need background tasks
Both approaches work well depending on your needs. Use the tasks package approach if you want to share tasks across multiple applications, or the app-based approach if tasks are specific to individual apps.

Approach 1: Tasks as a package (Turborepo)

This approach creates a dedicated tasks package that can be consumed by multiple apps in your monorepo.

1. Set up workspace configuration

Root package.json:
pnpm-workspace.yaml:
turbo.json:

2. Create the tasks package

packages/tasks/package.json:
packages/tasks/trigger.config.ts:
packages/tasks/src/index.ts:
packages/tasks/src/trigger/index.ts:
packages/tasks/src/trigger/example.ts:
See our turborepo-prisma-tasks-package example for a more complete example.

3. Use tasks in your apps

apps/web/package.json:
apps/web/app/api/actions.ts:

4. Development workflow

Run the development server for the tasks package:

Approach 2: Tasks in apps (Turborepo)

This approach installs Trigger.dev directly in individual apps that need background tasks.

1. Install in your app

apps/web/package.json:

2. Add configuration

apps/web/trigger.config.ts:

3. Create tasks

apps/web/src/trigger/example.ts:

4. Use tasks in your app

apps/web/app/api/actions.ts:

5. Development workflow

Example projects

You can find a growing list of example projects in our examples section.

Troubleshooting

If you run into any issues, please check our Troubleshooting page.

Feedback

If you have any feedback, please let us know by opening an issue.