Skip to content

Quick start

This guide creates a Kiln app, runs it in development, adds a page and an API route, and builds it for production.

1. Create the app

bash
bunx @kiln-js/cli create my-app

The command asks you a short series of questions:

  • Project name. Letters, numbers, -, and _ are allowed.
  • Template. Minimal creates one page. Starter adds an about page and a layout. Blog adds route groups, a loader, and a pricing page.
  • Rendering mode for the home page. universal (the default) renders on the server and hydrates in the browser. server sends HTML only. client renders only in the browser.
  • Example API route. When you accept, the project includes app/api/health.ts.
  • Extras. An .env file, and custom client and server entries.
  • Install dependencies now. When you accept, the CLI runs bun install.

When it finishes, it prints the next command.

2. Run the development server

bash
cd my-app
bun run dev

This runs kiln dev, which starts on port 3000 by default. Change the port with --port:

bash
bun run dev -- --port 4000

The development server renders pages on the server, hot-reloads the browser when a client file changes, and reloads the page when you add or remove a route file. When a page throws, the error appears in an overlay with the failing file, a code frame, and the stack trace.

3. Add a page

Create app/pages/about.tsx:

tsx
import { Link } from "@kiln-js/client";

export default function About() {
  return (
    <main>
      <kiln:title>About</kiln:title>
      <h1>About this app</h1>
      <p>This page is served at /about.</p>
      <Link href="/">Back home</Link>
    </main>
  );
}

Save the file. The route /about now exists. You do not need to edit any route table.

You can also generate the file with the CLI:

bash
bunx kiln generate page about

4. Add a loader

A loader runs on the server before the page renders and supplies its data prop. Create app/pages/posts/[slug].tsx:

tsx
export async function loader({ params }: { params: Record<string, string> }) {
  return { slug: params.slug, title: `Post: ${params.slug}` };
}

export default function Post({ data }: { data: { slug: string; title: string } }) {
  return (
    <article>
      <kiln:title>{data.title}</kiln:title>
      <h1>{data.title}</h1>
    </article>
  );
}

The URL /posts/hello matches [slug] and passes params.slug to the loader.

5. Add an API route

Create app/api/hello.ts:

ts
export function GET() {
  return Response.json({ message: "hello" });
}

Request /api/hello and you receive {"message":"hello"}.

6. Build for production

bash
bun run build
bun run start

kiln build writes the client bundle, the server bundle, and the manifest. kiln start serves the built output on port 3000. The start command also takes --port.

To deploy to Vercel, build with the Vercel target:

bash
bunx kiln build --target vercel

See Deploying for details.

Next steps