Prompt Buddy logoPrompt Buddy

cloudflare · Cloudflare Workers Docs

Workers Best Practices

Guidance on configuring Cloudflare Workers including managing compatibility dates, enabling Node.js compatibility, generating binding types, securing secrets, and configuring environments.

Import to Prompt Buddy

Derived skill

Files assembled from official documentation

Viewing SKILL.md

Workers Best Practices

Guidance on configuring Cloudflare Workers including managing compatibility dates, enabling Node.js compatibility, generating binding types, securing secrets, and configuring environments.

When To Use

Use when you need to configure a Cloudflare Worker for production readiness, manage environment secrets, or ensure type safety for bindings.

Reference Files

FileContainsUse For
SKILL.mdEntry point: scope, routing table, and workflow.Start here.
docs/workers-best-practices-workflow-guide.mdA guide outlining best practices for Cloudflare Workers configuration, including compatibility dates, Node.js compatibility, and binding type generation.Questions about a guide outlining best practices for Cloudflare Workers configuration, including compatibility dates, Node.js compati...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration.textA sample wrangler.toml configuration file demonstrating compatibility dates and Node.js compatibility flags for a Cloudflare Worker.Exact payloads, commands, or snippets shown in A sample wrangler.toml configuration file demonstrating compatibility dates and Node.js compatibility flags for a Clo...
examples/workers-best-practices-cloudflare-workers-best-practices-wrangler-toml-c.textA wrangler.toml configuration example demonstrating compatibility dates and nodejscompat flags for Cloudflare Workers.Exact payloads, commands, or snippets shown in A wrangler.toml configuration example demonstrating compatibility dates and nodejscompat flags for Cloudflare Workers.
examples/workers-best-practices-cloudflare-workers-wrangler-types-command.textA text example demonstrating the use of the npx wrangler types command for generating TypeScript definitions in a Cloudflare Workers project.Exact payloads, commands, or snippets shown in A text example demonstrating the use of the npx wrangler types command for generating TypeScript definitions in a Clo...
examples/workers-best-practices-cloudflare-workers-wrangler-types-command-2.textA text snippet demonstrating the command to generate TypeScript types using the Wrangler CLI for Cloudflare Workers.Exact payloads, commands, or snippets shown in A text snippet demonstrating the command to generate TypeScript types using the Wrangler CLI for Cloudflare Workers.
examples/workers-best-practices-cloudflare-workers-wrangler-types-command-3.textA text snippet demonstrating the command to generate TypeScript types for Cloudflare Workers using wrangler.Exact payloads, commands, or snippets shown in A text snippet demonstrating the command to generate TypeScript types for Cloudflare Workers using wrangler.
examples/workers-best-practices-cloudflare-workers-best-practices-env-typing.textA text example demonstrating the best practice of using wrangler-generated types for the environment object instead of manual definitions.Exact payloads, commands, or snippets shown in A text example demonstrating the best practice of using wrangler-generated types for the environment object instead o...
examples/workers-best-practices-cloudflare-workers-env-typing-best-practice.textA code example demonstrating how to use wrangler-generated types for the Env object to ensure bindings match configuration.Exact payloads, commands, or snippets shown in A code example demonstrating how to use wrangler-generated types for the Env object to ensure bindings match configur...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-be.textA wrangler.toml configuration example demonstrating the correct way to manage compatibility dates, flags, and environment variables versus secrets.Exact payloads, commands, or snippets shown in A wrangler.toml configuration example demonstrating the correct way to manage compatibility dates, flags, and environ...
examples/workers-best-practices-cloudflare-workers-best-practices-wrangler-toml-c-2.textA wrangler.toml configuration file demonstrating best practices for compatibility dates, flags, and environment variables.Exact payloads, commands, or snippets shown in A wrangler.toml configuration file demonstrating best practices for compatibility dates, flags, and environment varia...
examples/workers-best-practices-cloudflare-workers-secret-management-cli-command.textA command line instruction demonstrating how to use Wrangler to upload a secret environment variable to a Cloudflare Worker.Exact payloads, commands, or snippets shown in A command line instruction demonstrating how to use Wrangler to upload a secret environment variable to a Cloudflare...
examples/workers-best-practices-cloudflare-workers-best-practices-wrangler-secret.textA command line instruction demonstrating how to use Wrangler to securely set a secret environment variable in a Cloudflare Worker.Exact payloads, commands, or snippets shown in A command line instruction demonstrating how to use Wrangler to securely set a secret environment variable in a Cloud...
examples/workers-best-practices-cloudflare-workers-best-practices-wrangler-secret-2.textA command line instruction demonstrating how to use wrangler to set a secret environment variable in a Cloudflare Worker.Exact payloads, commands, or snippets shown in A command line instruction demonstrating how to use wrangler to set a secret environment variable in a Cloudflare Wor...
examples/workers-best-practices-cloudflare-workers-best-practices-cli-piping-secr.textExamples of piping output from CLI tools and environment variables into wrangler secret put commands.Exact payloads, commands, or snippets shown in Examples of piping output from CLI tools and environment variables into wrangler secret put commands.
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-2.textA sample wrangler.toml configuration file demonstrating environment bindings, compatibility dates, and KV namespace settings for a Cloudflare Worker.Exact payloads, commands, or snippets shown in A sample wrangler.toml configuration file demonstrating environment bindings, compatibility dates, and KV namespace s...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-3.textA sample wrangler.toml configuration file demonstrating compatibility dates, nodejscompat flags, and KV namespace bindings for different environments.Exact payloads, commands, or snippets shown in A sample wrangler.toml configuration file demonstrating compatibility dates, nodejscompat flags, and KV namespace bin...
examples/workers-best-practices-cloudflare-workers-deploy-staging-command.textA text command demonstrating how to deploy a Cloudflare Worker to a staging environment using the Wrangler CLI.Exact payloads, commands, or snippets shown in A text command demonstrating how to deploy a Cloudflare Worker to a staging environment using the Wrangler CLI.
examples/workers-best-practices-cloudflare-workers-best-practices-staging-deploym.textA text snippet demonstrating the wrangler command used to deploy Cloudflare Workers to a staging environment.Exact payloads, commands, or snippets shown in A text snippet demonstrating the wrangler command used to deploy Cloudflare Workers to a staging environment.
examples/workers-best-practices-cloudflare-workers-deploy-staging-command-2.textA command line instruction demonstrating how to deploy a Cloudflare Worker to a staging environment using pnpm and wrangler.Exact payloads, commands, or snippets shown in A command line instruction demonstrating how to deploy a Cloudflare Worker to a staging environment using pnpm and wr...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-4.textA wrangler.toml configuration file demonstrating custom domain routes and nodejscompat compatibility flags for a Cloudflare Worker.Exact payloads, commands, or snippets shown in A wrangler.toml configuration file demonstrating custom domain routes and nodejscompat compatibility flags for a Clou...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-5.textA sample wrangler.toml configuration file demonstrating compatibility dates, nodejscompat flags, and custom domain routing for a Cloudflare Worker.Exact payloads, commands, or snippets shown in A sample wrangler.toml configuration file demonstrating compatibility dates, nodejscompat flags, and custom domain ro...
examples/workers-best-practices-cloudflare-workers-memory-management-streaming-be.textA comparison of bad and good practices for handling large response bodies in Cloudflare Workers using streaming instead of memory buffering.Exact payloads, commands, or snippets shown in A comparison of bad and good practices for handling large response bodies in Cloudflare Workers using streaming inste...
examples/workers-best-practices-cloudflare-workers-memory-management-streaming-be-2.textA comparison of bad and good patterns for handling large response bodies in Cloudflare Workers using streaming instead of memory buffering.Exact payloads, commands, or snippets shown in A comparison of bad and good patterns for handling large response bodies in Cloudflare Workers using streaming instea...
examples/workers-best-practices-cloudflare-workers-sequential-stream-piping.textA JavaScript code example demonstrating how to sequentially pipe multiple response bodies using TransformStream to avoid memory buffering in Cloudflare Workers.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to sequentially pipe multiple response bodies using TransformStream to av...
examples/workers-best-practices-cloudflare-workers-sequential-streaming-best-prac.textA JavaScript code example demonstrating how to use TransformStream to pipe multiple response bodies sequentially without buffering to follow Cloudflare Workers best practices.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to use TransformStream to pipe multiple response bodies sequentially with...
examples/workers-best-practices-cloudflare-workers-best-practices-context-destruc.textA code example demonstrating why destructuring the context object in a Cloudflare Worker handler causes runtime errors due to lost this bindings.Exact payloads, commands, or snippets shown in A code example demonstrating why destructuring the context object in a Cloudflare Worker handler causes runtime error...
examples/workers-best-practices-cloudflare-workers-best-practices-context-destruc-2.textA code example demonstrating why destructuring the ExecutionContext object in a Cloudflare Worker causes runtime errors due to lost this binding.Exact payloads, commands, or snippets shown in A code example demonstrating why destructuring the ExecutionContext object in a Cloudflare Worker causes runtime erro...
examples/workers-best-practices-cloudflare-workers-rest-api-vs-binding-best-pract.textA comparison showing the incorrect method of calling the Cloudflare REST API versus the recommended method of using direct service bindings within a Worker.Exact payloads, commands, or snippets shown in A comparison showing the incorrect method of calling the Cloudflare REST API versus the recommended method of using d...
examples/workers-best-practices-cloudflare-workers-rest-api-fetch-anti-pattern.textA code example demonstrating the anti-pattern of calling the Cloudflare REST API directly from within a Worker instead of using a specialized binding.Exact payloads, commands, or snippets shown in A code example demonstrating the anti-pattern of calling the Cloudflare REST API directly from within a Worker instea...
examples/workers-best-practices-cloudflare-workers-best-practices-queue-vs-workfl.textA JavaScript code example demonstrating the architectural difference between using Cloudflare Queues for single-step background jobs and Workflows for multi-step durable processes.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating the architectural difference between using Cloudflare Queues for single-step...
examples/workers-best-practices-cloudflare-workers-best-practices-queue-vs-workfl-2.textA JavaScript code example demonstrating the architectural difference between using Cloudflare Queues for single-step background jobs and Workflows for multi-step processes.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating the architectural difference between using Cloudflare Queues for single-step...
examples/workers-best-practices-cloudflare-workers-rpc-service-binding.textA JavaScript code example demonstrating how to implement and call RPC methods between Workers using service bindings and the WorkerEntrypoint class.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to implement and call RPC methods between Workers using service bindings...
examples/workers-best-practices-cloudflare-workers-rpc-service-binding-2.textA TypeScript code example demonstrating how to implement and call RPC methods between Workers using service bindings and the WorkerEntrypoint class.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to implement and call RPC methods between Workers using service bindings...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-6.textA sample wrangler.toml configuration file demonstrating compatibility dates, flags, and Hyperdrive bindings for a Cloudflare Worker.Exact payloads, commands, or snippets shown in A sample wrangler.toml configuration file demonstrating compatibility dates, flags, and Hyperdrive bindings for a Clo...
examples/workers-best-practices-cloudflare-workers-best-practices-wrangler-toml-c-3.textA wrangler.toml configuration example demonstrating compatibility dates, compatibility flags, and Hyperdrive bindings for a Cloudflare Worker.Exact payloads, commands, or snippets shown in A wrangler.toml configuration example demonstrating compatibility dates, compatibility flags, and Hyperdrive bindings...
examples/workers-best-practices-cloudflare-workers-hyperdrive-pg-client-instantia.textA JavaScript code example demonstrating the correct way to instantiate a new PostgreSQL client per request when using Cloudflare Hyperdrive to leverage connection pooling.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating the correct way to instantiate a new PostgreSQL client per request when using...
examples/workers-best-practices-cloudflare-workers-hyperdrive-pg-client-instantia-2.textA TypeScript code example demonstrating the correct way to instantiate a PostgreSQL client per request when using Cloudflare Hyperdrive to leverage connection pooling.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating the correct way to instantiate a PostgreSQL client per request when using Clo...
examples/workers-best-practices-cloudflare-workers-durable-objects-websocket-rout.textA JavaScript code example demonstrating how to upgrade HTTP requests to WebSockets and route them to a Durable Object within a Cloudflare Worker.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to upgrade HTTP requests to WebSockets and route them to a Durable Object...
examples/workers-best-practices-cloudflare-workers-durable-objects-websocket-rout-2.textA TypeScript code example demonstrating how to upgrade an HTTP request to a WebSocket and route it to a Durable Object within a Cloudflare Worker.Exact payloads, commands, or snippets shown in A TypeScript code example demonstrating how to upgrade an HTTP request to a WebSocket and route it to a Durable Objec...
examples/workers-best-practices-cloudflare-workers-best-practices-static-site-wra.textA wrangler.toml configuration example demonstrating how to deploy a static site without a Worker script using the assets feature.Exact payloads, commands, or snippets shown in A wrangler.toml configuration example demonstrating how to deploy a static site without a Worker script using the ass...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-be-2.textA wrangler.toml configuration example demonstrating the use of compatibility dates, compatibility flags, and assets directory settings.Exact payloads, commands, or snippets shown in A wrangler.toml configuration example demonstrating the use of compatibility dates, compatibility flags, and assets d...
examples/workers-best-practices-cloudflare-workers-wrangler-toml-observability-co.textA wrangler.toml configuration snippet demonstrating observability settings including log and trace sampling rates.Exact payloads, commands, or snippets shown in A wrangler.toml configuration snippet demonstrating observability settings including log and trace sampling rates.
examples/workers-best-practices-cloudflare-workers-wrangler-toml-configuration-be-3.textA wrangler.toml configuration file demonstrating best practices for compatibility dates, nodejscompat flags, and observability settings.Exact payloads, commands, or snippets shown in A wrangler.toml configuration file demonstrating best practices for compatibility dates, nodejscompat flags, and obse...
examples/workers-best-practices-cloudflare-workers-best-practices-structured-logg.textA JavaScript code example demonstrating how to implement structured JSON logging within a Cloudflare Worker for better observability.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to implement structured JSON logging within a Cloudflare Worker for bette...
examples/workers-best-practices-cloudflare-workers-structured-logging-best-practi.textA JavaScript code example demonstrating how to implement structured JSON logging within a Cloudflare Worker fetch handler.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating how to implement structured JSON logging within a Cloudflare Worker fetch han...
examples/workers-best-practices-cloudflare-workers-best-practices-global-mutable-.textA code comparison demonstrating why global mutable state should be avoided in Cloudflare Workers to prevent data leakage between requests.Exact payloads, commands, or snippets shown in A code comparison demonstrating why global mutable state should be avoided in Cloudflare Workers to prevent data leak...
examples/workers-best-practices-cloudflare-workers-best-practices-global-mutable--2.textA code example demonstrating why using global mutable state in Cloudflare Workers leads to data leakage between requests.Exact payloads, commands, or snippets shown in A code example demonstrating why using global mutable state in Cloudflare Workers leads to data leakage between reque...
examples/workers-best-practices-cloudflare-workers-eslint-oxlint-best-practices.textESLint and Oxlint configuration commands for enforcing best practices such as preventing floating promises in Cloudflare Workers.Exact payloads, commands, or snippets shown in ESLint and Oxlint configuration commands for enforcing best practices such as preventing floating promises in Cloudfl...
examples/workers-best-practices-cloudflare-workers-best-practices-async-fetch-han.textA code example demonstrating the correct way to handle asynchronous fetch requests in Cloudflare Workers to avoid floating promises.Exact payloads, commands, or snippets shown in A code example demonstrating the correct way to handle asynchronous fetch requests in Cloudflare Workers to avoid flo...
examples/workers-best-practices-cloudflare-workers-best-practices-async-promise-h.textA code example demonstrating the correct way to handle asynchronous promises in Cloudflare Workers to prevent errors and swallowed results.Exact payloads, commands, or snippets shown in A code example demonstrating the correct way to handle asynchronous promises in Cloudflare Workers to prevent errors...
examples/workers-best-practices-cloudflare-workers-best-practices-javascript-secu.textA JavaScript code example demonstrating secure alternatives to predictable functions like Math.random() using the crypto API within a Cloudflare Worker.Exact payloads, commands, or snippets shown in A JavaScript code example demonstrating secure alternatives to predictable functions like Math.random() using the cry...
examples/workers-best-practices-cloudflare-workers-best-practices-javascript-patt.textA collection of JavaScript code examples demonstrating secure and efficient coding patterns for Cloudflare Workers, such as using crypto.randomUUID() instead of Math.random().Exact payloads, commands, or snippets shown in A collection of JavaScript code examples demonstrating secure and efficient coding patterns for Cloudflare Workers, s...
examples/workers-best-practices-cloudflare-workers-constant-time-token-verificati.textA JavaScript function demonstrating how to use SHA-256 hashing and constant-time comparison to securely verify tokens in a Cloudflare Worker.Exact payloads, commands, or snippets shown in A JavaScript function demonstrating how to use SHA-256 hashing and constant-time comparison to securely verify tokens...
examples/workers-best-practices-cloudflare-workers-best-practices-constant-time-t.textA JavaScript implementation demonstrating constant-time token verification using SHA-256 hashing to prevent timing attacks in Cloudflare Workers.Exact payloads, commands, or snippets shown in A JavaScript implementation demonstrating constant-time token verification using SHA-256 hashing to prevent timing at...
examples/workers-best-practices-cloudflare-workers-error-handling-best-practices.textA comparison of bad versus good error handling patterns in Cloudflare Workers using try-catch blocks and explicit responses.Exact payloads, commands, or snippets shown in A comparison of bad versus good error handling patterns in Cloudflare Workers using try-catch blocks and explicit res...
examples/workers-best-practices-cloudflare-workers-error-handling-best-practices-2.textA comparison of bad versus good error handling patterns in Cloudflare Workers using passThroughOnException versus explicit structured responses.Exact payloads, commands, or snippets shown in A comparison of bad versus good error handling patterns in Cloudflare Workers using passThroughOnException versus exp...
examples/workers-best-practices-cloudflare-workers-vitest-kv-best-practices.textA Vitest test suite demonstrating best practices for performing KV storage and retrieval operations in Cloudflare Workers.Exact payloads, commands, or snippets shown in A Vitest test suite demonstrating best practices for performing KV storage and retrieval operations in Cloudflare Wor...

What This Skill Covers

  • Best practices for Workers based on production patterns, Cloudflare's own internal usage, and common issues seen across the developer community.
  • Main sections: Configuration, Keep your compatibility date current, Enable nodejs\compat, Generate binding types with wrangler types, Store secrets with wrangler secret, not in source.

Workflow

  1. Open the most relevant file under docs/ for the exact documented workflow and wording.
  2. Open schemas/ files for exact structured contracts.
  3. Open examples/ files for concrete requests, commands, snippets, and manifests.
  4. Do not add behavior or configuration that is not present in the attached source files.

Canonical source: https://developers.cloudflare.com/workers/best-practices/workers-best-practices