Skip to content

Quickstart ​

A first app with two routes, started on your runtime.

Install ​

bash
npm install routup
npm pkg set type=module

The second line marks the project as ESM, so Node.js loads server.ts without a module type warning. Other package managers and the requirements are on Installation.

Write the App ​

app.ts defines the routes and starts nothing, so a test or another runtime can use the same file:

ts
import { App, defineCoreHandler } from 'routup';

export const app = new App();

app.get('/', defineCoreHandler(() => 'Hello, World!'));

app.get('/users/:id', defineCoreHandler((event) => ({ id: event.params.id })));

server.ts starts it:

typescript
import { serve } from 'routup';
import { app } from './app.ts';

serve(app);

Run It ​

bash
node server.ts
bash
bun server.ts
bash
deno run --allow-net --allow-env server.ts
bash
npx wrangler dev
  • Node.js runs .ts files directly from 22.18 (and 23.6 on the 23 line). On an older 22 release, run npx tsx server.ts. Node needs the .ts extension in relative imports.
  • Deno: the permission flags are explained on Runtime Environments.
  • Cloudflare Workers use a different server.ts: a module worker exports the server instead of starting it. The Cloudflare Workers example has the worker file and the wrangler.jsonc; wrangler dev listens on port 8787.

The server listens on port 3000 by default (serve options).

bash
curl http://localhost:3000/
# Hello, World!

curl http://localhost:3000/users/42
# {"id":"42"}

What a Handler Returns ​

The string became a text/plain response and the object a JSON response. Every other value a handler can return (a Response, a stream, binary data, null) is listed on Response.

Next Steps ​