Getting Started
Create a new project
bash
npm create export my-app
cd my-app
npm installThis scaffolds a project with everything you need:
my-app/
├── src/
│ └── index.ts # Your exports
├── package.json
├── wrangler.toml
└── tsconfig.jsonWrite your exports
Open src/index.ts and write whatever you want to expose:
typescript
export async function greet(name: string) {
return `Hello, ${name}!`;
}
export function add(a: number, b: number) {
return a + b;
}
export class Counter {
private count: number;
constructor(initial = 0) { this.count = initial; }
increment() { return ++this.count; }
getCount() { return this.count; }
}Every named export becomes remotely callable. Sync functions automatically become async on the client.
Run locally
bash
npm run devThis starts a local Wrangler dev server. You can now import from http://localhost:8787/:
javascript
import { greet } from "http://localhost:8787/";
await greet("World"); // "Hello, World!"Deploy
bash
npm run exportThis generates type definitions, minifies the client, and deploys to Cloudflare Workers. Your exports are now live at your Worker URL.
Next steps
- Path-based imports -- import individual exports
- Classes -- remote class instantiation
- Streaming -- AsyncIterator and ReadableStream
- Shared Exports -- cross-client shared state