···11+# Project: Hop
22+33+Cloudflare Workers project built with Bun.
44+55+## Stack
66+77+- **Runtime**: Cloudflare Workers
88+- **Package Manager**: Bun
99+- **Language**: TypeScript
1010+1111+## Commands
1212+1313+```sh
1414+bun run dev # Start local dev server (wrangler dev)
1515+bun run deploy # Deploy to Cloudflare
1616+bun run types # Generate Cloudflare Workers types
1717+bun test # Run tests
1818+```
1919+2020+## Architecture
2121+2222+- Worker entry point: `src/index.ts`
2323+- Configuration: `wrangler.toml`
2424+- Compatibility date: `2024-12-11`
2525+2626+## Bun Preferences
2727+2828+Default to using Bun instead of Node.js.
2929+3030+- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
3131+- Use `bun test` instead of `jest` or `vitest`
3232+- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
3333+- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
3434+- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
3535+- Use `bunx <package> <command>` instead of `npx <package> <command>`
3636+- Bun automatically loads .env, so don't use dotenv.
3737+3838+## Bun APIs
3939+4040+- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
4141+- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
4242+- `Bun.redis` for Redis. Don't use `ioredis`.
4343+- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
4444+- `WebSocket` is built-in. Don't use `ws`.
4545+- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
4646+- Bun.$`ls` instead of execa.
4747+4848+**Note**: When building for Cloudflare Workers, use Web Standard APIs (Request, Response, fetch) instead of Bun-specific APIs, as they won't be available in the Workers runtime.
4949+5050+## Cloudflare Workers Development
5151+5252+Workers use the standard Fetch API handler:
5353+5454+```ts
5555+export default {
5656+ async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
5757+ return new Response('Hello World');
5858+ },
5959+} satisfies ExportedHandler<Env>;
6060+```
6161+6262+### Environment Variables
6363+6464+Define bindings in `wrangler.toml` and access via the `env` parameter:
6565+6666+```toml
6767+[vars]
6868+MY_VAR = "value"
6969+7070+[[kv_namespaces]]
7171+binding = "MY_KV"
7272+id = "..."
7373+```
7474+7575+```ts
7676+interface Env {
7777+ MY_VAR: string;
7878+ MY_KV: KVNamespace;
7979+}
8080+```
8181+8282+### Testing
8383+8484+Use `bun test` with Cloudflare Workers types:
8585+8686+```ts
8787+import { test, expect } from "bun:test";
8888+8989+test("worker responds", async () => {
9090+ const request = new Request("http://localhost/");
9191+ const response = await worker.fetch(request, {}, {});
9292+ expect(response.status).toBe(200);
9393+});
9494+```
9595+9696+For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`.