Installation
@basmilius/worker targets the Cloudflare Workers runtime and ships as ESM. Install it alongside Luxon, which is used for DateTime parsing in queryDate.
shell
bun add @basmilius/worker luxonshell
npm install @basmilius/worker luxonshell
pnpm add @basmilius/worker luxonshell
yarn add @basmilius/worker luxonCloudflare Workers context
The package is designed for the Workers runtime — it relies only on the standard Request and Response globals plus URL. You can deploy a worker entry-point by exporting the value returned by createWorker as the module's default export:
ts
// src/index.ts
import { createWorker, json } from '@basmilius/worker';
export default createWorker({
'/api/health': async () => json({ok: true})
});Pair it with a wrangler.toml and you are ready to deploy:
toml
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-09-01"TypeScript
The package ships its own declarations. Pair it with the official @cloudflare/workers-types to get types for bindings such as D1Database, KVNamespace and R2Bucket:
shell
bun add -d @cloudflare/workers-typesjsonc
// tsconfig.json
{
"compilerOptions": {
"types": ["@cloudflare/workers-types"]
}
}Requirements
- A bundler that emits ESM modules (Wrangler does this by default)
- A modern runtime providing
Request,Response,URLandsetTimeout— Cloudflare Workers, Bun, Deno