Skip to content

Quick start

Install the router, write a first service, and serve it on Cloudflare Workers, Node, Deno or Bun.

Start with the router and the HTTP building blocks; add other packages when you need them.

npm install @edgetime/router @edgetime/http

Keep the routes in a module that imports nothing from a platform. Each runtime then gets a small entry file that serves them.

src/app.ts
import { errorHandler, readJson } from '@edgetime/http';
import { Router } from '@edgetime/router';
export const app = new Router()
.get('/health', (c) => c.json({ status: 'ok' }))
.get('/hello/:name', (c) => c.text(`Hello, ${c.params.name}`))
.post('/echo', async (c) => {
const body = await readJson(c.req, { limit: 16 * 1024 });
return c.json({ received: body }, 201);
})
.onError(errorHandler());

app.fetch(request, env?, ctx?) never rejects and always resolves to a Response. A path that is not registered gets 404; one registered under another method gets 405 with Allow. A body over the limit gets 413 and malformed JSON 400. errorHandler() renders every error as RFC 9457 problem details.

src/index.ts
import { app } from './app.ts';
export default { fetch: app.fetch } satisfies ExportedHandler;
wrangler.jsonc
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-service",
"main": "src/index.ts",
"compatibility_date": "2026-11-27"
}
npx wrangler dev

The router passes env and ctx through to handlers as c.env and c.ctx. See Deploy on Workers for bindings and the composition root.

npm install @edgetime/node
src/server.ts
import { serve } from '@edgetime/node';
import { app } from './app.ts';
const server = await serve(app.fetch, { port: 3000, env: {} });
process.once('SIGTERM', async () => process.exit((await server.shutdown()) ? 0 : 1));
node src/server.ts

Node 24.13 runs TypeScript sources directly. See Run on Node.

Both serve fetch handlers natively. Pass only the request, since their second argument is not an env:

// Deno
Deno.serve((request) => app.fetch(request));
// Bun
Bun.serve({ fetch: (request) => app.fetch(request) });