Installing Required Packages
Start by installing the necessary packages in your Express.js project directory. You can use npm, pnpm, or yarn as your package manager.Ensure that you execute this command within a Express project.
Obtaining the Development Server API Key
To locate your development Server 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 Server 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.
Configuring the Trigger Client
Create a file for your Trigger client, in this case we create it at<root>/trigger.(ts/js)
trigger.(ts/js)
Adding the API endpoint
There are a few different options depending on how your Express project is configured.- App middleware
- Entire app for Trigger.dev (only relevant if it's the only thing your project is for)
Creating the Example Job
Create a Job file. In this case created<root>/jobs/example.(ts/js)
jobs/example.(ts/js)
Adding Configuration to package.json
Inside the package.json
file, add the following configuration under the root object:
Running
Run your Express app
Run your Express app locally, like you normally would. For example:You might use
npm run start
instead of devRun 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 Express is running on 0.0.0.0: --hostname 0.0.0.0
.