Getting Started

Configuration

What tenon.config.ts is, the smallest config, the environment variables, how Vite fits in and the routes Tenon adds.

This page explains the one file every Tenon project has, and what Tenon adds to your app. For every option, see the configuration reference.

tenon.config.ts

tenon.config.ts sits in the root of your project. It default-exports one CMS instance, made by defineCms(). Everything Tenon knows comes from this file: your content types, the database, users, media and the admin.

Three things read it:

  • Your pages import the instance to read content, like cms.find("posts").
  • The framework integration serves the API and the admin from it.
  • The tenon CLI loads it for backups, users and upgrades.

defineCms() checks the config when it loads. If something is missing or invalid, the server stops at startup with an error. See Startup checks.

The smallest config

Only database and secret are required:

tenon.config.ts
import { defineCms } from "tenoncms";
import { sqlite } from "tenoncms/sqlite";

export default defineCms({
  database: sqlite("./cms.db"),
  secret: process.env.TENON_SECRET!,
});
  • database: where content and users are stored. sqlite() uses Node's built-in SQLite, so there is nothing to install. Tenon creates cms.db on the first request. For other databases, see Databases.
  • secret: signs sessions and tokens. It needs at least 32 characters.

This already gives you a working admin, users, a media library in ./.uploads and the Settings page. It has no content types yet.

Add a collection right in the config:

tenon.config.ts
import { defineCms } from "tenoncms";
import { sqlite } from "tenoncms/sqlite";

export default defineCms({
  database: sqlite("./cms.db"),
  secret: process.env.TENON_SECRET!,
  collections: {
    posts: {
      fields: {
        title: { type: "text", required: true },
      },
    },
  },
});

The key posts is the name you pass to find("posts"). The starters move each collection into its own file in collections/ with defineCollection(). See Collections and globals.

Environment variables

Tenon reads no environment variable at runtime. tenon.config.ts passes every value, so you decide where it comes from. The starters use these names:

VariableRequiredWhat it is
TENON_SECRETYesThe value of secret. Generate one with openssl rand -hex 32.
TENON_SITE_URLNoThe value of site.url, the public origin. Set it in production only.

Each framework loads them in its own way:

Declare the variables in the env schema of astro.config.ts, and import them from astro:env/server. Astro checks them at startup.

astro.config.ts
import { defineConfig, envField } from "astro/config";

export default defineConfig({
  env: {
    schema: {
      TENON_SECRET: envField.string({ context: "server", access: "secret", min: 32 }),
      TENON_SITE_URL: envField.string({
        context: "server",
        access: "secret",
        url: true,
        optional: true,
      }),
    },
  },
});
tenon.config.ts
import { TENON_SECRET, TENON_SITE_URL } from "astro:env/server";

export default defineCms({
  secret: TENON_SECRET,
  site: { url: TENON_SITE_URL, name: "My Site" },
  // ...
});

In development, the dev server loads .env. In production, npm start loads it with Node's --env-file-if-exists=.env, or you set the variables on the host.

Site URL

site.url is the public origin of your site, like https://example.com. It has no path. The sitemap, robots.txt, preview links, sign-in and links into the admin use it.

Leave it unset in development. Tenon then uses the origin of each request, so localhost works on any port. Set it in production.

site.name is the name the admin, emails and passkeys show.

If your site and the CMS run on different origins, also set auth.baseURL to the CMS origin. See Authentication.

Variables of the CLI

The tenon CLI reads two more, to work against a deployed site instead of the local config:

  • TENON_URL: the URL of the deployed site.
  • TENON_API_KEY: an API key for that site.

See the CLI.

How Vite fits in

Tenon runs inside your app. tenon.config.ts is a normal module: a server route imports it, and your app's Vite build compiles it like any other file.

  • Astro and Nuxt: the integration adds the routes and the admin for you.
  • TanStack Start and other Vite frameworks: tenonAdmin() from tenoncms/vite builds the admin, and you write the route files.

How Tenon works explains what happens under the hood.

Routes Tenon adds

RouteServes
/_tenon/*The HTTP API: content, media files, sign-in, users and the admin's data.
/adminThe admin. Change the path with admin.path, or turn it off with admin: false.
/sitemap.xmlEvery published document of each collection with a permalink. Turn it off with sitemap: false.
/robots.txtAllows the site except /_tenon, and points to the sitemap. Turn it off with robots: false.

Astro and Nuxt add all four. If your app already serves /sitemap.xml or /robots.txt, Tenon leaves that route to your app. On TanStack Start, each route is a file in src/routes/, and the sitemap and robots.txt need one more file each. See TanStack Start.

Every API route is listed in the HTTP routes reference.