Build with Hono
Create a Hono project with the Azion CLI, run it locally, and deploy it to an Azion domain.
Use the Azion CLI to create a Hono project from a template, run it on your computer, and deploy it. When the deploy ends, the project runs on Azion and answers on an Azion domain.
Azion runs a Hono project as a function. The azion init picker offers Hono as a starting point, and the project builds with the typescript preset. The deploy creates a function, a function instance, and a rule that runs the function on every request. It creates no storage bucket. For the other frameworks that Azion builds, refer to Frameworks compatibility.
Prerequisites
- An Azion account. To create one, refer to Create an account.
- The Azion CLI, installed and logged in. For the setup, refer to Azion CLI quickstart.
- Node.js 18 or later, with npm.
- A terminal and a code editor.
Deploy the project
The CLI creates the project, builds it, runs it locally, and creates the resources that serve it on Azion.
To create the project, run azion init with a name:
The command asks its questions in order. Give these answers:
- At
Choose a preset:, select Hono. You can typeHonoto filter the list. - At
Choose a template:, select Hono Boilerplate. This guide uses that template. - At
Do you want to install project dependencies?, answerY. - At
Do you want to start a local development server?, answern. - At
Do you want to deploy your project?, answern.
For every question and the flags that skip them, refer to Azion CLI init. The command prints this output:
The project is in the my-app folder. Its azion.config.ts file sets the typescript preset and src/index.ts as the entry. For every setting in that file, refer to azion.config.js. The entry holds the Hono app:
The template’s package.json has no dev or build script. Use azion dev and azion build instead.
To build the project, go to the project folder and run azion build:
Azion Bundler builds the entry with the typescript preset and writes one function file to .edge/functions/index.js. The build prints a warning about the handler pattern and completes:
To run the project on your computer, run azion dev from the project folder:
The command builds the project again and serves the function on port 3333:
In a second terminal, request the local server:
The function returns the text of the Hono route:
The server keeps running until you stop it. For the flags of the command, refer to Azion CLI dev.
To deploy the project, run azion deploy from the project folder:
The CLI uploads the project and opens a Console page where you can follow the deploy. If the browser does not open, use the URL of that page, which the CLI also prints. At the end, the CLI prints the URL of the project’s domain:
The deploy creates a function and a function instance. It also creates an application with a rule named Execute Function, which runs the function on every request, and a workload that serves the application on the domain. The output does not list them; azion/azion.json in the project folder records their IDs. For the flags of the command, refer to Azion CLI deploy.
Check the project
At the end of the deploy, azion deploy prints the URL of the project’s Azion domain, in the form https://xxxxxxxxxx.map.azionedge.net. Request that URL, with your domain in place of <your-domain>:
After the deploy reaches the location that answers your request, the function returns the Hono route:
The first deploy can take several minutes to answer from every location. Until a location receives the project, the domain answers with a 404 page that reads There's nothing here yet, and that page can return for a while after the first successful response. If you get that page, wait and request the URL again.
The function answers every path. A path that the Hono app does not define returns the plain-text 404 Not Found of Hono, not the There's nothing here yet page.