Getting Started

Add to an Existing Site

Add Tenon to an Astro, Nuxt or TanStack Start app you already have.

If you already have an existing app, you can add Tenon to it. For specific examples and details to adding a database, storage, email and more, please look at the specific sections inside the docs. For demonstrative purposes and to keep it simple, this tutorial uses SQLite as the database and node as the target deployment.

To start from scratch instead, see the Quick Start.

Install the packages

Install Tenon and the SQLite driver (or use the built in node:sqlite and skip libsql):

npm install tenoncms @libsql/client

Tenon runs on the server, so your app needs a server build. Nuxt needs nothing else. Astro and TanStack Start need one more package:

npm install @astrojs/node

Add a collection

A collection is a list of documents with the same fields. Create a file for a posts collection:

cms/collections/posts.ts
import { defineCollection } from "tenoncms";

export const posts = defineCollection({
  titleField: "title",
  fields: {
    title: { type: "text", required: true },
    slug: { type: "slug", from: "title", required: true, unique: true },
    body: { type: "textarea" },
  },
});

See Fields for information on field types and options.

Create the CMS instance

Create tenon.config.ts at the project root. It reads the secret and the database URL from environment variables. Each framework reads them in its own way:

import { DATABASE_URL, TENON_SECRET, TENON_SITE_URL } from "astro:env/server";
import { defineCms } from "tenoncms";
import { libsql } from "tenoncms/libsql";
import { posts } from "./cms/collections/posts";

export default defineCms({
  collections: { posts },
  database: libsql(DATABASE_URL),
  secret: TENON_SECRET,
  site: { url: TENON_SITE_URL, name: "My Site" },
});

For what each option does, see Configuration.

Connect the framework

The framework setup adds the API at /_tenon, the admin at /admin, and gives your pages the CMS instance:

Add the integration, and declare the variables in the env schema:

astro.config.ts
import node from "@astrojs/node";
import { defineConfig, envField } from "astro/config";
import tenonCms from "tenoncms/astro";

export default defineConfig({
  adapter: node({ mode: "standalone" }),
  integrations: [tenonCms()],
  env: {
    schema: {
      TENON_SECRET: envField.string({ context: "server", access: "secret", min: 32 }),
      DATABASE_URL: envField.string({
        context: "server",
        access: "secret",
        default: "file:./cms.db",
      }),
      TENON_SITE_URL: envField.string({
        context: "server",
        access: "secret",
        url: true,
        optional: true,
      }),
    },
  },
});

The integration finds tenon.config.ts at the project root.

Set the secret

Tenon signs sessions with a secret of at least 32 characters. Generate one:

openssl rand -hex 32

Put it in .env at the project root:

.env
TENON_SECRET=<your secret>

Keep the secret, the database and the uploads out of git:

.gitignore
.env
cms.db*
.uploads

Create the admin account

Start the dev server, open the URL it prints and add /admin. Enter your name, email and a password, then select Create admin account.

The first account is the admin. Create a post, then select Publish. Every save is a draft until you publish it.

Show the posts on a page

Read the posts on a page. The page runs on the server and calls Tenon directly, without HTTP:

---
export const prerender = false;

const posts = await Astro.locals.tenon.find("posts");
---

<h1>Posts</h1>
<ul>
  {posts.map((post) => <li>{post.title}</li>)}
</ul>

Open /blog. It lists the post you published. post.title is typed from the collection, so your editor completes it and flags a typo.

In Astro, prerender = false makes the page read the content on each request. A prerendered page reads it once, at build time.

Next steps

Your framework

Integration options, components, live preview and locale routing.

Content modeling

All field types, relations between collections, and blocks for page sections.

Media

Turn on uploads and responsive images.