Tutorial

Build and ship a site with Hoosat Create

This walkthrough takes you from an empty folder to a deployed, server-rendered React site. It is exactly how create.hoosat.fi was made, and every code sample comes from its source.

View the full source on GitHub

Before you start

You need Node.js 22, 24 or 26 and git. Check your versions:

$ node --version
v24.22.3
$ git --version
git version 2.55.0

Older Node.js versions can not run the build tools, which are TypeScript files executed directly by Node.

Create the project

Run the generator and answer its questions, or pass the answers as arguments:

$ npx hoosat-create@latest
# or answer the questions up front:
$ npx hoosat-create@latest --destination my-site --author "Your Name" --license MIT --gitInit Y

The script clones hoosat-template with the hoosat-server-core submodule, writes your details into package.json, runs npm install and can initialise a git repository for you.

Start the dev server

npm run dev builds into build-dev, starts the server and rebuilds whenever you save a file in src or public.

$ cd my-site
$ npm run dev
Server is running on port 8181

Open http://localhost:8181. The port comes from PORT in .env.

Find your way around

Everything lives in src, split by where the code runs. Client and server code are never mixed in the same file, so the folder tells you what ends up in the browser:

my-site/
├── public/                 static files, copied into the build
├── src/
│   ├── client/             React app: App.tsx, routes/, components/, *.css
│   ├── common/             code shared by server and client
│   ├── server/
│   │   ├── api-routes/     your API endpoints
│   │   ├── core/           hoosat-server-core (git submodule)
│   │   └── index.tsx       the server itself
│   └── __tests__/          Jest tests
├── build-tools/            TypeScript build helpers run by Node
├── webpack.client.config.js
└── webpack.server.config.js

src/server/core is a git submodule shared by every Hoosat project. Update it with git submodule update --remote instead of editing it in place.

Add a page

Pages are ordinary React components. Create one under src/client/routes:

// src/client/routes/Pricing.tsx
import { Helmet } from "react-helmet-async";

export const Pricing = () => (
  <section>
    <Helmet>
      <title>Pricing</title>
      <meta name="description" content="Plans for every team." />
    </Helmet>
    <h1>Pricing</h1>
  </section>
);

Then add it to the route list in src/client/App.tsx. The browser router and the server share that list, and the server uses it to answer unknown URLs with a real 404 status.

// src/client/App.tsx
export const routes: RouteObject[] = [
  { path: "/", element: <Home /> },
  { path: "/tutorial", element: <Tutorial /> },
  { path: "/pricing", element: <Pricing /> },
  { path: "*", element: <NotFound /> },
];

Add an API route

API routes use the core router. Create a router, add handlers and mount it in src/server/api-routes/index.ts:

// src/server/api-routes/hello/hello.ts
import { createRouter } from "../../core/server";

export const helloRouter = createRouter();

helloRouter.Get("/api/hello/:name", (req, res) => {
  res.status(200).json({ message: "Hello, " + req.params!["name"] });
});

// src/server/api-routes/index.ts
APIRouter.UseRouter(helloRouter);

Path parameters are in req.params, and res.status(), res.send() and res.json() cover most responses.

Set titles and meta tags

Put head tags inside <Helmet> anywhere in a page. On the server the renderer streams them into <head> before the body, so search engines and link previews see them without JavaScript.

// src/client/components/Seo.tsx (shortened)
export const Seo = ({ title, description, path }: SeoProps) => (
  <Helmet>
    <title>{title}</title>
    <meta name="description" content={description} />
    <link rel="canonical" href={absoluteUrl(path)} />
    <meta property="og:title" content={title} />
    <meta property="og:description" content={description} />
  </Helmet>
);

This site keeps all of it in one Seo component that also writes the canonical URL, Open Graph and JSON-LD tags.

Style it

Drop plain .css files anywhere under src/client. The build merges and minifies them into /public/styles.css, which the renderer links in every page. No imports needed.

/* src/client/styles/00-tokens.css (shortened) */
:root {
  --bg: #f7f8fb;
  --text: #0e1525;
  --accent: #0b7a6e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0d14;
    --text: #e8ecf3;
    --accent: #34d3bf;
  }
}

This site defines its colours as CSS custom properties, so dark and light mode are one media query.

Translate it

The template ships i18next on both sides. This site picks the language per request, from a cookie or the Accept-Language header:

// src/server/index.tsx: choose the language for this request
const lng = pickLanguage(req.headers.cookie, req.headers['accept-language']);
renderer({ res, jsx: <Document url={url} lng={lng} />, publicDir });

// src/client/index.tsx: hydrate with the language the server used
const i18n = createI18n(document.documentElement.lang);

Translations are bundled and initialised synchronously, so the server and the browser produce identical markup and hydration never flashes untranslated keys.

Test it

Tests live in src/__tests__ and run with Jest. Type check the whole project separately:

$ npm test
Tests:       19 passed, 19 total
$ npm run typecheck

This site's tests cover the language picker, the sitemap, the 404 handling, a full server render and that both languages have the same keys.

Build and deploy

npm run build writes a production build into build, including precompressed copies of every asset. Webpack bundles the server and its dependencies into build/server.js, so production only needs that folder:

$ npm run build
$ npm start
Server is running on port 8181

Put the server behind a reverse proxy such as Caddy or nginx for TLS, or run it as a container with the Dockerfile in the repository:

$ docker build -t create-hoosat-fi .
$ docker run -d -p 3070:3070 --restart unless-stopped create-hoosat-fi

That's it: a server-rendered React site in production, built from code you understand.