Express
How to get setup and deploy Jobs for your Express project
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.
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 with tr_dev_
).
Adding Environment Variables
Create a .env
file at the root of your project and include your Trigger API key and URL like this:
Replace 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)
Replace "my-app" with an appropriate identifier for your project.
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)
Select the appropriate code example from below:
Creating the Example Job
Create a Job file. In this case created <root>/jobs/example.(ts/js)
Adding Configuration to package.json
Inside the package.json
file, add the following configuration under the root object:
Replace "my-app" with the appropriate identifier you used in the trigger.js configuration file.
Running
Run your Express app
Run your Express app locally, like you normally would. For example:
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 end
You 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
.
Was this page helpful?