How to manually setup Trigger.dev in your Next.js project
Don't have a Next.js project yet to add Trigger.dev to? No problem, you can complete the Manual Setup using a blank Next.js project:
create-next-app
command in your terminal:tr_dev_
).
.env.local
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.
<root>/src/trigger.ts
or <root>/trigger.ts
depending on whether you’re using the src
directory or not. <root>
represents the root directory of your project.
Next, add the following code to the file which creates and exports a new TriggerClient
:
route.(ts/js)
within the app/api/trigger/
directory.route.(ts/js)
:Jobs
alongside your app
or pages
directoryJobs
folder, add two files named example.(ts/js)
and index.(ts/js)
.Jobs
folder and exporting them in index
file.
For example, in index.(ts/js)
, you can export other job files like this:
package.json
package.json
file, add the following configuration under the root object:
package.json
file might look something like this:
--port 3001
to the end--hostname <host>
. Example, in case your Remix is running on 0.0.0.0: --hostname 0.0.0.0
.