Server kit
Start a pure backend: h3 server, API routes, logger, database and realtime channels, no React.
For: Backend developers who want an API, jobs or a realtime service with no React in the project.
kitr new my-app --kit serverFirst time? Run npm i -g @kitr/kitr once. Inside a project, the global kitr runs your project's own version.
- kitr dev
- The API on port 3001, restarted on change
- kitr build
- A Node build in
dist/api - npm test
- Vitest, starting with the API test
Routes and controllers
server/routes.ts maps URLs to controllers in server/controllers/, with a health check to start.
Any database
config/db.ts connects the ORM you pick, with Drizzle and postgres.js sketched in its comments.
Live channels
app/channels/example.ts is a typed channel clients can subscribe to.
Tested without a running server
test/example.test.ts calls the API in memory with createTestClient.
What's inside
Read from the kit's output in the kitr repository, so it matches what kitr new writes today. 5 packages · 23 files.
Every file it writes
Start with server/routes.ts. Pick any file to read it.
import { defineRoutes } from '@kitr/kitr/app'
import api from '@kitr/api/routes'
import realtime from '@kitr/realtime/routes'
import HealthController from '#server/controllers/health-controller'
import { exampleChannel } from '#app/channels/example'
/**
* Endpoints and sockets of this app. `kitr add` keeps the extension list current; `createServer({ routes })`
* in server/main.ts serves it.
*/
export const routes = defineRoutes([api, realtime], (root) =>
root.group('/api', (r) =>
r.get('/health', [HealthController, 'show'], { name: 'health' }),
// r.resource('projects', () => import('#server/controllers/projects-controller'))
)
.ws('/ws', { channels: [exampleChannel] /* , authorize: (request) => ... */ }),
)
/** Pass to createApiClient<ServerRoutes>() on the client. */
export type ServerRoutes = typeof routes.$types