Skip to main content
Install Hono in an existing project to start building web applications with this ultrafast framework.

Install Hono

Add Hono to your project using your preferred package manager:
npm install hono

Basic Setup

Once installed, create your first Hono application:
index.ts
import { Hono } from 'hono'

const app = new Hono()

app.get('/', (c) => c.text('Hono!'))

export default app

Package Exports

Hono provides multiple entry points for different use cases. Here are the most common imports:

Core Framework

import { Hono } from 'hono'
import type { Context, Handler, MiddlewareHandler } from 'hono'
import { HTTPException } from 'hono/http-exception'

Middleware

import { cors } from 'hono/cors'
import { logger } from 'hono/logger'
import { basicAuth } from 'hono/basic-auth'
import { jwt } from 'hono/jwt'
import { compress } from 'hono/compress'
import { csrf } from 'hono/csrf'
import { etag } from 'hono/etag'
import { secureHeaders } from 'hono/secure-headers'

Helpers

import { setCookie, getCookie } from 'hono/cookie'
import { stream, streamSSE } from 'hono/streaming'
import { html } from 'hono/html'
import { validator } from 'hono/validator'

Runtime Adapters

import { serveStatic } from 'hono/cloudflare-workers'
import { serveStatic } from 'hono/bun'
import { serveStatic } from 'hono/deno'

Presets

Hono offers optimized presets for different use cases. These presets use different routers under the hood for specific performance characteristics.

Standard (Default)

The default import uses SmartRouter which combines RegExpRouter and TrieRouter for optimal performance:
import { Hono } from 'hono'

const app = new Hono()
This is the recommended preset for most applications. It provides:
  • Excellent routing performance
  • Support for all routing patterns
  • Automatic router selection based on route complexity

Tiny Preset

For applications where bundle size is critical (under 12kB), use the tiny preset with PatternRouter:
import { Hono } from 'hono/tiny'

const app = new Hono()
Characteristics:
  • Smallest bundle size (under 12kB)
  • Zero dependencies
  • Uses only Web Standard APIs
  • Ideal for Cloudflare Workers and edge environments

Quick Preset

For simpler applications with linear routing needs, use the quick preset with LinearRouter:
import { Hono } from 'hono/quick'

const app = new Hono()
Characteristics:
  • Uses LinearRouter combined with TrieRouter
  • Optimized for applications with fewer routes
  • Good balance between size and performance
The choice of preset mainly affects routing performance and bundle size. The API remains the same across all presets.

Runtime-Specific Setup

Depending on your deployment target, you may need additional setup:
No additional setup required. Just export your app:
import { Hono } from 'hono'

const app = new Hono()
app.get('/', (c) => c.text('Hello Cloudflare!'))

export default app
Add to your wrangler.toml:
name = "my-hono-app"
main = "src/index.ts"
compatibility_date = "2024-01-01"

TypeScript Configuration

For the best development experience with TypeScript, ensure your tsconfig.json includes:
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ES2022",
    "moduleResolution": "bundler",
    "lib": ["ES2022"],
    "types": ["@cloudflare/workers-types"],
    "jsx": "react-jsx",
    "jsxImportSource": "hono/jsx",
    "strict": true,
    "skipLibCheck": true
  }
}
Adjust the types field based on your runtime. For Node.js, use ["node"]. For Deno, this field is not needed.

Package.json Setup

Here’s a minimal package.json for a Hono project:
package.json
{
  "name": "my-hono-app",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "dev": "wrangler dev src/index.ts",
    "deploy": "wrangler deploy --minify src/index.ts"
  },
  "dependencies": {
    "hono": "^4.12.0"
  },
  "devDependencies": {
    "wrangler": "^3.0.0"
  }
}
Make sure to set "type": "module" in your package.json to enable ES modules support.

Verifying Installation

Test that Hono is correctly installed by running a simple script:
test.ts
import { Hono } from 'hono'

const app = new Hono()
app.get('/', (c) => c.text('Installation successful!'))

// Test the app
const res = await app.request('http://localhost/')
console.log(await res.text()) // Should output: Installation successful!
Run it:
node test.ts
# or
bun test.ts
# or
deno run test.ts

Next Steps

Now that Hono is installed, you’re ready to build:

Quickstart Guide

Build your first Hono application

Routing

Learn about routes and path patterns

Middleware

Explore built-in and custom middleware

API Reference

Dive into the complete API documentation

Build docs developers (and LLMs) love