Quick Start
Create a new Hono project for Cloudflare Workers:Installation
If you’re adding Hono to an existing Cloudflare Workers project:Basic Usage
Create your application insrc/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 theserveStatic middleware:
WebSocket Support
Upgrade HTTP connections to WebSocket:Connection Info
Get connection information including IP address:Configuration
wrangler.toml
Configure your Worker withwrangler.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.devDevelopment
Run your Worker locally:http://localhost:8787.
Environment Variables
Add secrets for sensitive data:Best Practices
Keep bundle size small
Keep bundle size small
Workers have a size limit. Use tree-shaking and avoid large dependencies.
Use TypeScript
Use TypeScript
TypeScript provides excellent type safety for bindings and context.
Handle errors gracefully
Handle errors gracefully
Always implement error handling as Workers run at the edge.
Leverage caching
Leverage caching
Use Cache API and KV for better performance.
Resources
Cloudflare Workers Docs
Official Cloudflare Workers documentation
Wrangler CLI
Learn more about the Wrangler CLI