98 lines
3.7 KiB
Plaintext
98 lines
3.7 KiB
Plaintext
---
|
|
title: "Quick start: add Trigger.dev to your project"
|
|
sidebarTitle: "Quick start"
|
|
description: "Set up Trigger.dev in your existing project in under 3 minutes. Install the SDK, create your first background task, and trigger it from your code."
|
|
---
|
|
|
|
import CliInitStep from "/snippets/step-cli-init.mdx";
|
|
import CliDevStep from "/snippets/step-cli-dev.mdx";
|
|
import CliRunTestStep from "/snippets/step-run-test.mdx";
|
|
import CliViewRunStep from "/snippets/step-view-run.mdx";
|
|
|
|
## Set up with AI
|
|
|
|
Using an AI coding assistant? Copy this prompt and paste it into Claude Code, Cursor, Copilot, Windsurf, or any AI tool. It'll handle the setup for you.
|
|
|
|
<Accordion title="Copy the setup prompt">
|
|
|
|
```text
|
|
Help me add Trigger.dev to this project.
|
|
|
|
## What to do
|
|
|
|
1. I need a Trigger.dev account. If I don't have one, point me to https://cloud.trigger.dev to sign up. Wait for me to confirm.
|
|
2. Run `npx trigger.dev@latest init` in the project root.
|
|
- When it asks about the MCP server, recommend I install it (best DX: gives you direct access to Trigger.dev docs, deploys, and run monitoring).
|
|
- Install the "Hello World" example task when prompted.
|
|
3. Run `npx trigger.dev@latest dev` to start the dev server.
|
|
4. Once the dev server is running, test the example task from the Trigger.dev dashboard.
|
|
5. Set TRIGGER_SECRET_KEY in my .env file (or .env.local for Next.js). I can find it on the API Keys page in the dashboard.
|
|
6. Ask me what framework I'm using and show me how to trigger the task from my backend code.
|
|
|
|
If I've already run init and want the MCP server, run: npx trigger.dev@latest install-mcp
|
|
|
|
## Critical rules
|
|
|
|
- ALWAYS import from `@trigger.dev/sdk`. NEVER import from `@trigger.dev/sdk/v3`.
|
|
- NEVER use `client.defineJob()` — that's the deprecated v2 API.
|
|
- Use type-only imports when triggering from backend code to avoid bundling task code:
|
|
|
|
import type { myTask } from "./trigger/example";
|
|
import { tasks } from "@trigger.dev/sdk";
|
|
|
|
const handle = await tasks.trigger<typeof myTask>("hello-world", { message: "Hello from my app!" });
|
|
|
|
## When done, point me to
|
|
|
|
- Writing tasks: https://trigger.dev/docs/tasks/overview
|
|
- Real-time updates: https://trigger.dev/docs/realtime/overview
|
|
- AI tooling: https://trigger.dev/docs/building-with-ai
|
|
```
|
|
|
|
</Accordion>
|
|
|
|
## Manual setup
|
|
|
|
<Steps titleSize="h3">
|
|
|
|
<Step title="Create a Trigger.dev account">
|
|
|
|
Sign up at [Trigger.dev Cloud](https://cloud.trigger.dev) (or [self-host](/self-hosting/overview)). The onboarding flow will guide you through creating your first organization and project.
|
|
|
|
</Step>
|
|
|
|
<CliInitStep />
|
|
<CliDevStep />
|
|
<CliRunTestStep />
|
|
<CliViewRunStep />
|
|
|
|
</Steps>
|
|
|
|
## Triggering tasks from your app
|
|
|
|
The test page in the dashboard is great for verifying your task works. To trigger tasks from your own code, you'll need to set the `TRIGGER_SECRET_KEY` environment variable. Grab it from the API Keys page in the dashboard and add it to your `.env` file.
|
|
|
|
```bash .env
|
|
TRIGGER_SECRET_KEY=tr_dev_...
|
|
```
|
|
|
|
See [Triggering](/triggering) for the full guide, or jump straight to framework-specific setup for [Next.js](/guides/frameworks/nextjs), [Remix](/guides/frameworks/remix), or [Node.js](/guides/frameworks/nodejs).
|
|
|
|
## Next steps
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Building with AI" icon="brain" href="/building-with-ai">
|
|
Build Trigger.dev projects using AI coding assistants
|
|
</Card>
|
|
<Card title="How to trigger your tasks" icon="bolt" href="/triggering">
|
|
Trigger tasks from your backend code
|
|
</Card>
|
|
<Card title="Writing tasks" icon="wand-magic-sparkles" href="/tasks/overview">
|
|
Task options, lifecycle hooks, retries, and queues
|
|
</Card>
|
|
<Card title="Guides and example projects" icon="books" href="/guides/introduction">
|
|
Framework guides and working example repos
|
|
</Card>
|
|
|
|
</CardGroup>
|