Platform · server

Server

An HTTP API with routes, controllers and live channels, on Node, Bun, Deno or Cloudflare Workers. With React or without it.

  • Node
  • Bun
  • Deno
  • Workers
kitr add server api --runtime node

First time? Run npm i -g kitr once. Inside a project, the global kitr runs your project's own version.

Built onH3
// server/routes.ts
import { defineRoutes } from 'kitr/api'
import HealthController from '#server/controllers/health_controller'
import OrdersController from '#server/controllers/orders_controller'

export const routes = defineRoutes((router) =>
  router.group({ prefix: '/api' }, (api) =>
    api
      .get('/health', [HealthController, 'show'], { name: 'health' })
      .resource('orders', OrdersController),
  ),
)

/** The client your pages call is typed from this. */
export type AppRoutes = typeof routes.$types

Four runtimes, one option

runtime: 'bun', 'deno' or 'workers' changes how kitr dev and kitr build run the same server/main.ts. Workers deploy through wrangler.toml.

A typed client, no codegen

Routes and controllers live in server/routes.ts. The client your pages call is typed from that table, so a renamed field is a type error, not a bug report.

Inside your site or beside it

A project with a web platform also gets app/routes/api.$.ts, which mounts the same server inside TanStack Start. Run it there, or as its own process.

No React required

kitr new my-api --kit server has no React anywhere in its dependency graph: an h3 server, routes, a database hook, logs and tests.

Same commands as every platform

Every platform answers to kitr dev, kitr build and kitr start, by the name you gave it. Leave the name off to run them all.

kitr dev api
tsx watch, bun --watch or wrangler dev, by runtime
kitr build api
a bundled server in dist/api
kitr start api
runs the compiled server

Packages that work here

12 packages run on server. Each one is a single kitr add away.

All packages →

Learn more

Start from a kit

A kit sets up the platforms, the packages and a first page in one command. Kits with server: server, fullstack, saas.

kitr new my-app --kit server

First time? Run npm i -g kitr once. Inside a project, the global kitr runs your project's own version.

Add another platform

Platforms share the app/ folder, so adding one is a command, not a rewrite.

Mix and match →