Hono Quick Start
Start creating Jobs in 5 minutes in your Hono project.
Hono is a fast & lightweight web framework built on top of Web Standards, and we support using Hono with Trigger.dev on Cloudflare Workers, Bun, Deno, and Node.js.
Installing Required Packages
To begin, install the necessary packages in your Hono project:
Obtain 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_
).
Configure Environment Variables
Add the following environment variables to your .env
file (or .dev.vars
file if you are using Cloudflare Workers):
Replace <development server api key>
with the actual API key obtained from the previous step.
Enable Node.js compatibility
If you are using Cloudflare Workers, you’ll need to enable Node.js compatibility mode in your wrangler.toml
file:
Add Middelware to Your Hono app
Our @trigger.dev/hono
package provides two different ways of configuring the necessary middleware needed to connect your Hono app to Trigger.dev. addMiddleware
which should be used for Cloudflare Workers, and createMiddleware
which can be used with Bun, Deno, and Node.js.
Cloudflare Workers
Because environment variables in Cloudflare Workers aren’t available in the global scope, but are instead available only inside the fetch handler, we need to use the addMiddleware
function to add the necessary middleware to your Hono app.
The second argument to addMiddleware
is a function that receives the environment variables (either from .dev.vars
in development or from Cloudflare when deployed), and returns a TriggerClient
instance. This function will be called once per request.
If you want, you can extract our the function that creates the TriggerClient
instance into a separate file, and import it into your index.ts
file:
Now that you’ve created the TriggerClient
and setup the middleware, you can add your first job:
As you can see above in jobs.ts
, we define our first job using the new Job
constructor from @trigger.dev/sdk
, and then in trigger-client.ts
we attach the job to the TriggerClient
instance.
Bun
If you are using Bun, you can use the createMiddleware
function to create the necessary middleware to connect your Hono app to Trigger.dev and define your TriggerClient
and jobs in the global scope:
Deno
Import trigger.dev packages with Deno using npm: specifiers:
To load a .env
file on startup, pass the deno run
command a --env
flag:
You can also load an environment variables file in code using the dotenv
package:
In which case you need to pass the --allow-env
and --allow-read
flags:
Now we can create the TriggerClient
, define our jobs, and create the middleware:
Node.js
Node.js works very similarly to Deno and Bun, in that you can define the TriggerClient
and jobs in the global scope, and then create the middleware and add it to your Hono app:
Running
Cloudflare Workers
Run your Hono app locally, like you normally would. For example:
In a separate terminal window or tab run:
Bun
Run your Hono app locally, like you normally would. For example:
In a separate terminal window or tab run:
Deno
Run your Hono app locally, like you normally would. For example:
In a separate terminal window or tab run:
Node.js
Run your Hono app locally, like you normally would. For example:
In a separate terminal window or tab run:
Was this page helpful?