cloudflare

Cloudflare Workers, KV, D1, R2, Pages, and Wrangler CLI. Use when deploying to the edge, configuring Workers, managing storage bindings, or setting up Cloudflare Pages.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "cloudflare" with this command: npx skills add oakoss/agent-skills/oakoss-agent-skills-cloudflare

Cloudflare

Overview

Cloudflare Workers is a serverless edge compute platform that runs JavaScript, TypeScript, and WebAssembly on Cloudflare's global network. Workers use the ES modules format with fetch, scheduled, and queue event handlers, and access platform services (KV, D1, R2, Durable Objects) through environment bindings.

When to use: Edge-first APIs, low-latency global apps, serverless functions, static site hosting with Pages, key-value caching, relational data at the edge, object storage without egress fees.

When NOT to use: Long-running compute exceeding CPU time limits, workloads requiring persistent TCP connections, applications needing full Node.js API compatibility, large monolithic applications better suited to containers.

Quick Reference

PatternAPI / ConfigKey Points
Fetch handlerexport default { fetch(request, env, ctx) }Entry point for HTTP requests
Scheduled handlerexport default { scheduled(controller, env, ctx) }Cron triggers via [triggers] in config
Environment variablesenv.VAR_NAMESet in wrangler.toml or dashboard
KV read/writeenv.KV.get(key) / env.KV.put(key, value)Eventually consistent, 25 MiB max value
D1 queryenv.DB.prepare(sql).bind(...params).all()SQLite at the edge, prepared statements
D1 batchenv.DB.batch([stmt1, stmt2])Atomic transaction, single round trip
R2 uploadenv.BUCKET.put(key, body)S3-compatible, no egress fees
R2 downloadenv.BUCKET.get(key)Returns R2ObjectBody with ReadableStream
Durable Objectsenv.DO.get(id) then stub.fetch(request)Single-instance stateful coordination
DO storagethis.ctx.storage.sql.exec(query)SQLite backend recommended for new DOs
Pages deploywrangler pages deploy <dir>Static + Functions, auto-generated routes
Worker deploywrangler deployReads wrangler.toml for config
Dev serverwrangler devLocal development with bindings
Secretswrangler secret put SECRET_NAMEEncrypted, not in wrangler.toml
Static assetsassets: { directory: "./dist" }Served without invoking Worker by default
Workflowsexport class MyWorkflow extends WorkflowEntrypointDurable multi-step execution engine
Hyperdriveenv.HYPERDRIVE.connectionStringConnection pooling for external PostgreSQL
Queues produceenv.QUEUE.send(message)Async message passing between Workers
Config formatwrangler.jsonc (recommended for new projects)JSON with comments; preferred over TOML

Common Mistakes

MistakeCorrect Pattern
Accessing bindings as globalsAccess via env parameter in module format
Storing secrets in wrangler.tomlUse wrangler secret put for encrypted values
Using KV for strong consistencyUse D1 or Durable Objects for consistent reads
Not binding parameters in D1 queriesAlways use .prepare().bind() to prevent SQL injection
Exceeding KV value size (25 MiB)Use R2 for objects larger than 25 MiB
Forgetting await on storage operationsKV, D1, R2 methods are all async
Using fetch() without passing signalPass request.signal for automatic cancellation
Creating D1 database in Worker codeCreate with wrangler d1 create, bind in config
Missing compatibility_date in configAlways set to avoid breaking changes
Returning non-Response from fetch handlerMust return a Response object
Using wrangler.toml for new projectsUse wrangler.jsonc for new projects; has better IDE support
Using KV for relational queriesUse D1 for SQL queries; KV is key-value only

Delegation

  • Architecture review: Use Task agent to evaluate edge vs origin patterns
  • Code review: Delegate to code-reviewer agent
  • Storage selection: Use Explore agent to compare KV vs D1 vs R2 vs DO

References

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

github-cli

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

tanstack-cli

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

typescript-patterns

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

tanstack-devtools

No summary provided by upstream source.

Repository SourceNeeds Review