Skip to main content
Cloudflare Workers is an edge computing platform that runs JavaScript at Cloudflare’s global network. Hono works perfectly with Cloudflare Workers with zero configuration.

Quick Start

Create a new Hono project for Cloudflare Workers:
Select “cloudflare-workers” as your template when prompted.

Installation

If you’re adding Hono to an existing Cloudflare Workers project:

Basic Usage

Create your application in src/index.ts:
src/index.ts
Cloudflare Workers expects your application to be exported as default. Hono’s app object is a valid fetch handler.

Adapter Features

The Cloudflare Workers adapter provides several utilities:

Static Files

Serve static files using the serveStatic middleware:

WebSocket Support

Upgrade HTTP connections to WebSocket:

Connection Info

Get connection information including IP address:

Configuration

wrangler.toml

Configure your Worker with wrangler.toml:
wrangler.toml

Accessing Bindings

Access Cloudflare bindings through the context:

Deployment

1

Install Wrangler

Install the Cloudflare Workers CLI:
2

Login to Cloudflare

Authenticate with your Cloudflare account:
3

Deploy

Deploy your application:
Your app will be available at https://my-hono-app.<your-subdomain>.workers.dev

Development

Run your Worker locally:
This starts a local development server with hot reload at http://localhost:8787.

Environment Variables

Add secrets for sensitive data:
Access secrets in your code:

Best Practices

Workers have a size limit. Use tree-shaking and avoid large dependencies.
TypeScript provides excellent type safety for bindings and context.
Always implement error handling as Workers run at the edge.
Use Cache API and KV for better performance.

Resources

Cloudflare Workers Docs

Official Cloudflare Workers documentation

Wrangler CLI

Learn more about the Wrangler CLI