Don't have a NestJS project yet to add Trigger.dev to? No problem, you can complete the Manual Setup using a blank NestJS project:
Don't have a NestJS project yet to add Trigger.dev to? No problem, you can complete the Manual Setup using a blank NestJS project:
Create a blank project by installing the NestJS CLI in your terminal:Then, create an empty project with:
Installing Required Packages
To begin, install the necessary packages in your NestJS project directory. You can choose one of the following package managers:Ensure that you execute this command within a NestJS project.
Obtaining the Development API Key
To locate your development API key, login to the Trigger.dev dashboard and select the Project you want to connect to. Then click on the Environments & API Keys tab in the left menu. You can copy your development API Key from the field at the top of this page. (Your development key will start withtr_dev_
).
Adding Environment Variables
Create a.env
file at the root of your project and include your Trigger API key and URL like this:
ENTER_YOUR_DEVELOPMENT_API_KEY_HERE
with the actual API key obtained from the previous step.
This configuration only will be loaded if you use NestJS
Config or
dotenv.
Adding TriggerDev Module
Open yourapp.module.ts
, and add the following inside your imports
:
Creating the Example Job
When you addTriggerDevModule
to your project, you will can have access to the TriggerClient
instance by using the @InjectTriggerDevClient()
decorator in the constructor.
Now, let's create an example job to test the integration.
- Create a controller named
job.controller.ts
alongside yourapp.module.ts
- Inside that controller, add the following code:
You can import the Trigger.dev client inside any
service
or controller
, we recommend you to
create specialized service
for each job you have for a better maintainability.Adding Configuration to package.json
Inside the package.json
file, add the following configuration under the root object:
package.json
file might look something like this:
Running
Run your NestJS app
Run your NestJS app locally, like you normally would. For example:Run the CLI 'dev' command
In a separate terminal window or tab run:You can optionally pass the port if you're not running on 3000 by adding
--port 3001
to the endYou can optionally pass the hostname if you're not running on localhost by adding
--hostname <host>
. Example, in case your Remix is running on 0.0.0.0: --hostname 0.0.0.0
.