Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/elysiajs/documentation/llms.txt

Use this file to discover all available pages before exploring further.

Elysia supports Cloudflare Workers through an experimental Cloudflare Worker adapter. The adapter enables Ahead of Time (AoT) compilation, taking advantage of Cloudflare’s support for function compilation during startup introduced in compatibility date 2025-06-01.
Cloudflare Worker support is currently experimental.
1

Initialize a new Worker project with Wrangler

You need Wrangler to scaffold and run your Worker locally.
wrangler init elysia-on-cloudflare
2

Add the CloudflareAdapter to your app

Import CloudflareAdapter from elysia/adapter/cloudflare-worker, pass it as the adapter option, and call .compile() before exporting.
import { Elysia } from 'elysia'
import { CloudflareAdapter } from 'elysia/adapter/cloudflare-worker'

export default new Elysia({
  adapter: CloudflareAdapter
})
  .get('/', () => 'Hello Cloudflare Worker!')
  .compile()
Calling .compile() is required for Elysia to work on Cloudflare Workers.
3

Set compatibility_date in your Wrangler config

AoT compilation requires compatibility_date set to at least 2025-06-01.
{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "elysia-on-cloudflare",
  "main": "src/index.ts",
  "compatibility_date": "2025-06-01"
}
4

Start the development server

wrangler dev
The development server starts at http://localhost:8787.

Bindings

Access Cloudflare Workers bindings by importing env from cloudflare:workers:
import { Elysia } from 'elysia'
import { CloudflareAdapter } from 'elysia/adapter/cloudflare-worker'
import { env } from 'cloudflare:workers'

export default new Elysia({
  adapter: CloudflareAdapter
})
  .get('/', () => `Hello ${await env.KV.get('my-key')}`)
  .compile()
See Cloudflare Workers: Bindings for the full list of supported binding types.

Static files

The Static Plugin does not work on Cloudflare Workers due to the absence of the fs module. Use Cloudflare’s built-in static asset serving instead. Add the assets field to your Wrangler config:
{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "elysia-on-cloudflare",
  "main": "src/index.ts",
  "compatibility_date": "2025-06-01",
  "assets": { "directory": "public" }
}
Place your static files in the public folder. Given the following structure:
├── public
│   ├── kyuukurarin.mp4
│   └── static
│       └── mika.webp
├── src
│   └── index.ts
└── wrangler.toml
Files will be accessible at /kyuukurarin.mp4 and /static/mika.webp.

Limitations

LimitationDetails
Elysia.file and Static PluginNot supported — no fs module available
OpenAPI Type GenNot supported — no fs module available
Inline response valuesCannot define Response before server start
// This will throw an error on Cloudflare Workers
new Elysia()
  .get('/', 'Hello Elysia')
  .listen(3000)

pnpm peer dependencies

If you use pnpm, install peer dependencies manually:
pnpm add @sinclair/typebox openapi-types

Build docs developers (and LLMs) love