Skip to main content

Worker

A Cloudflare Worker is a serverless function that runs on Cloudflare’s global network.

Props

string
The entrypoint for the worker script.
string
Inline worker script (alternative to entrypoint).
string
Name for the worker.
Bindings
Bindings to attach to the worker.
boolean
default:"false"
Whether to enable a workers.dev URL for this worker.If true, the worker will be available at {name}.{subdomain}.workers.dev
(string | RouteConfig)[]
Routes to create for this worker.
(string | DomainConfig)[]
Custom domains to bind to the worker.
string
The compatibility date for the worker.
string[]
The compatibility flags for the worker.
CompatibilityPreset
Compatibility preset to automatically include common compatibility flags.
  • "node": Includes nodejs_compat flag for Node.js compatibility
string[]
Cron expressions for the trigger. Uses standard cron syntax.
EventSource[]
Event sources that this worker will consume.
AssetsConfig
Configuration for static assets.
WorkerPlacement
Placement configuration for the worker.
object
Resource limits for the worker.
WorkerObservability
Specify the observability behavior of the Worker.
boolean
default:"false"
Enable Workers Logpush to export trace events to external destinations.Requires a separate Logpush job configuration via the Cloudflare API.
string
Version label for this worker deployment.When specified, the worker will be published as a version with this label instead of updating the live deployment.

Output

string
The ID of the worker.
string
The name of the worker.
string
The worker’s URL if enabled. Format: {name}.{subdomain}.workers.dev
Bindings
The bindings that were created.
Route[]
The routes that were created for this worker.
CustomDomain[]
The custom domains that were created for this worker.
string
The compatibility date for the worker.
string[]
The compatibility flags for the worker.

Examples

Basic HTTP Handler

Worker with Bindings

Worker with Custom Domain

Scheduled Worker

Queue Consumer