Setting the file. One moment.
Chapter 04 · Cloudflare Deploy
Subchapter 4.290
references/workers/README.mdMarkdown3 KBView on GitHub
Expert guidance for building, deploying, and optimizing Cloudflare Workers applications.
Cloudflare Workers run on V8 isolates (NOT containers/VMs):
Key principle: Workers use web platform APIs wherever possible for portability.
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
return new Response('Hello World!');
},
};Handler parameters:
request: Incoming HTTP request (standard Request object)env: Environment bindings (KV, D1, R2, secrets, vars)ctx: Execution context (waitUntil, passThroughOnException)npx wrangler dev # Local dev
npx wrangler dev --remote # Remote dev (actual resources)
npx wrangler deploy # Production
npx wrangler deploy --env staging # Specific environment
npx wrangler tail # Stream logs
npx wrangler secret put API_KEY # Set secretnpm create cloudflare@latest my-worker -- --type hello-world
cd my-worker
npx wrangler dev// HTTP requests
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response>
// Cron triggers
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void>
// Queue consumer
async queue(batch: MessageBatch, env: Env, ctx: ExecutionContext): Promise<void>
// Tail consumer
async tail(events: TraceItem[], env: Env, ctx: ExecutionContext): Promise<void>Docs: https://developers.cloudflare.com/workers/ (opens in a new tab)
Examples: https://developers.cloudflare.com/workers/examples/ (opens in a new tab)
Runtime APIs: https://developers.cloudflare.com/workers/runtime-apis/ (opens in a new tab)
| Task | Start With | Then Read |
|---|---|---|
| First Worker | README → Configuration → API | Patterns |
| Add framework | Frameworks | Configuration (bindings) |
| Add storage/bindings | Configuration → API (binding usage) | See Also links |
| Debug issues | Gotchas | API (specific binding docs) |
| Production optimization | Patterns | API (caching, streaming) |
| Type safety | Configuration (TypeScript) | Frameworks (Hono typing) |