Skip to content

What is export?

export lets you write normal functions and classes on a Cloudflare Worker, then import them from any client -- browser, Node.js, Deno, or another Worker -- using just the Worker URL.

javascript
// On the server: write functions as usual
export function greet(name) {
  return `Hello, ${name}!`;
}

// On the client: import from the Worker URL
import { greet } from "https://my-worker.workers.dev/";
await greet("World");  // "Hello, World!"

No SDK. No code generation. No client-side build step.

Two Ways to Use

New Project

bash
npm create export my-app
cd my-app && npm install
npm run dev

Existing Vite Project

bash
npx exportc init
cd export && npm install && cd ..
npm run dev

The Vite plugin auto-starts Wrangler, auto-generates TypeScript types, and deploys to Workers Sites with npm run export.

How it works

  1. Your Worker exports functions and classes in src/index.ts
  2. When a client imports the Worker URL, a tiny ESM glue module is returned
  3. That module opens a WebSocket and creates Proxy objects for each export
  4. Function calls are serialized with devalue and sent over WebSocket
  5. Results come back as promises

The core client library (~5KB) is served with immutable caching and changes path on each deploy for automatic cache busting.

Key features

  • Zero-config client -- just import from a URL
  • Vite integration -- npm run dev starts everything, types auto-generated
  • Path-based imports -- import greet from ".../greet"
  • Static assets -- serve HTML, CSS, and images alongside your API
  • Client storage -- access D1, R2, KV directly from the browser
  • Classes -- remote instantiation with Comlink-style proxies
  • Streaming -- ReadableStream and AsyncIterator support
  • Shared exports -- cross-client shared state via Durable Objects
  • TypeScript -- precise types generated at build time with oxc-parser
  • Rich serialization -- Date, Map, Set, BigInt, URL, TypedArrays, and more
  • Single config -- everything in package.json, wrangler.toml is auto-generated

Released under the MIT License.