Skip to main content
The trigger.config.ts file is used to configure your Trigger.dev project. It is a TypeScript file at the root of your project that exports a default configuration object. Here’s an example:
trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
  // Your project ref (you can see it on the Project settings page in the dashboard)
  project: "<project ref>",
  //The paths for your trigger folders
  dirs: ["./trigger"],
  retries: {
    //If you want to retry a task in dev mode (when using the CLI)
    enabledInDev: false,
    //the default retry settings. Used if you don't specify on a task.
    default: {
      maxAttempts: 3,
      minTimeoutInMs: 1000,
      maxTimeoutInMs: 10000,
      factor: 2,
      randomize: true,
    },
  },
});
The config file handles a lot of things, like:
  • Specifying where your trigger tasks are located using the dirs option.
  • Setting the default retry settings.
  • Configuring OpenTelemetry instrumentations.
  • Customizing the build process.
  • Adding global task lifecycle functions.
The config file is bundled with your project, so code imported in the config file is also bundled, which can have an effect on build times and cold start duration. One important qualification is anything defined in the build config is automatically stripped out of the config file, and imports used inside build config with be tree-shaken out.

Dirs

You can specify the directories where your tasks are located using the dirs option:
trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
  project: "<project ref>",
  dirs: ["./trigger"],
});
If you omit the dirs option, we will automatically detect directories that are named trigger in your project, but we recommend specifying the directories explicitly. The dirs option is an array of strings, so you can specify multiple directories if you have tasks in multiple locations. We will search for TypeScript and JavaScript files in the specified directories and include them in the build process. We automatically exclude files that have .test or .spec in the name, but you can customize this by specifying glob patterns in the ignorePatterns option:
trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
  project: "<project ref>",
  dirs: ["./trigger"],
  ignorePatterns: ["**/*.my-test.ts"],
});

Custom tsconfig path

You can specify a custom path to your tsconfig file. This is useful if you have a custom tsconfig file that you want to use.
trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
  project: "<project ref>",
  dirs: ["./trigger"],
  tsconfig: "./custom-tsconfig.json", // Custom tsconfig path
});

Lifecycle functions

You can add lifecycle functions to get notified when any task starts, succeeds, or fails using onStart, onSuccess and onFailure:
trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";

export default defineConfig({
  project: "<project ref>",
  // Your other config settings...
  onSuccess: async ({ payload, output, ctx }) => {
    console.log("Task succeeded", ctx.task.id);
  },
  onFailure: async ({ payload, error, ctx }) => {
    console.log("Task failed", ctx.task.id);
  },
  onStart: async ({ payload, ctx }) => {
    console.log("Task started", ctx.task.id);
  },
  init: async ({ payload, ctx }) => {
    console.log("I run before any task is run");
  },
});
Read more about task lifecycle functions in the tasks overview.

Instrumentations

We use OpenTelemetry (OTEL) for our run logs. This means you get a lot of information about your tasks with no effort. But you probably want to add more information to your logs. For example, here’s all the Prisma calls automatically logged: