Skip to content
Our Sponsors

Cloudflare Worker Experimental

Elysia now supports Cloudflare Worker with an experimental Cloudflare Worker Adapter.

  1. You will need Wrangler to setup, and start a development server.
bash
wrangler init elysia-on-cloudflare
  1. Then add Cloudflare Adapter to your Elysia app, and make sure to call .compile() before exporting the app.
ts
import { Elysia } from 'elysia'
import { CloudflareAdapter } from 'elysia/adapter/cloudflare-worker'

export default new Elysia({
	adapter: CloudflareAdapter 
})
	.get('/', () => 'Hello Cloudflare Worker!')
	// This is required to make Elysia work on Cloudflare Worker
	.compile() 
  1. Make sure to have compatibility_date set to at least 2025-06-01 in your wrangler config
jsonc
{
	"$schema": "node_modules/wrangler/config-schema.json",
 	"name": "elysia-on-cloudflare",
	"main": "src/index.ts",
	"compatibility_date": "2025-06-01"
}
toml
main = "src/index.ts"
name = "elysia-on-cloudflare"
compatibility_date = "2025-06-01"
  1. Now you can start the development server with:
bash
wrangler dev

This should start a development server at http://localhost:8787

You don't need a nodejs_compat flag as Elysia doesn't use any Node.js built-in modules (or the ones we use don't support Cloudflare Worker yet).

Limitations

Here are some known limitations of using Elysia on Cloudflare Worker:

  1. Elysia.file, and Static Plugin doesn't work due to the lack of fs module
  2. OpenAPI Type Gen doesn't work due to the lack of fs module
  3. You can't define Response before server start, or use plugin that does so
  4. You can't inline a value
typescript
import { Elysia } from 'elysia'

new Elysia()
	// This will throw error
    .get('/', 'Hello Elysia')
    .listen(3000)

Static File

Static Plugin doesn't work, but you can still serve static files with Cloudflare's built-in static file serving.

Add the following to your wrangler config:

jsonc
{
	"$schema": "node_modules/wrangler/config-schema.json",
 	"name": "elysia-on-cloudflare",
	"main": "src/index.ts",
	"compatibility_date": "2025-06-01",
	"assets": { "directory": "public" } 
}
toml
name = "elysia-on-cloudflare"
main = "src/index.ts"
compatibility_date = "2025-06-01"
assets = { directory = "public" } 

Create a public folder and place your static files in it.

For example, if you have a folder structure like this:


├─ public
│  ├─ kyuukurarin.mp4
│  └─ static
│     └─ mika.webp
├─ src
│  └── index.ts
└─ wrangler.toml

Then you should be able to access your static file from the following path:

Binding

You can use a Cloudflare Workers binding by importing env from cloudflare:workers.

ts
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: Binding for more information about binding.

AoT compilation

Previously, to use Elysia on Cloudflare Worker, you have to pass aot: false to the Elysia constructor.

This is no longer necessary as Cloudflare now supports Function compilation during startup.

As of Elysia 1.4.7, you can now use Ahead of Time Compilation with Cloudflare Worker, and drop the aot: false flag.

ts
import { Elysia } from 'elysia'
import { CloudflareAdapter } from 'elysia/adapter/cloudflare-worker'

export default new Elysia({
	aot: false, 
	adapter: CloudflareAdapter 
})

Otherwise, you can still use aot: false if you don't want Ahead of Time Compilation but we recommend you to use it for better performance, and accurate plugin encapsulation.