---
title: "initQino"
description: "Initialize the instance that all definitions hang off."
canonical: "https://www.qino.works/docs/api/init-qino"
---

# initQino

> Initialize the instance that all definitions hang off.

Initializes a qino instance bound to a content folder and a media folder. Every collection, tree, and item is defined through the returned instance.

```ts title="qino/index.ts"
import { initQino } from "@qino/cms";

const qino = initQino({
  contentFolder: "src/content",
  mediaFolder: "public",
  cli: {
    check: { localAssetReferences: { exclude: ["/og/**"] } },
  },
  cloud: {
    publish: { mode: "open_pull_request", reviewBeforePublish: true },
  },
});
```

## Signature

```ts title="@qino/cms"
function initQino(config: {
  readonly contentFolder: string;
  readonly mediaFolder: string;
  readonly siteUrl?: string;
  readonly cli?: {
    readonly check?: {
      readonly localAssetReferences?:
        boolean | { readonly exclude?: ReadonlyArray<string> };
    };
    readonly build?: {
      readonly types?: boolean;
      readonly llmsTxt?:
        boolean | { readonly template?: string; readonly sections?: boolean };
    };
  };
  readonly cloud?: {
    readonly publish:
      | {
          readonly mode: "open_pull_request";
          readonly reviewBeforePublish:
            boolean | { readonly bypassIfAdmin?: boolean };
          readonly branchPrefix?: string;
        }
      | {
          readonly mode: "commit_to_default_branch";
          readonly reviewBeforePublish:
            boolean | { readonly bypassIfAdmin?: boolean };
        };
  };
  readonly incrementalEntries?: boolean;
}): {
  defineCollection: typeof defineCollection;
  defineTree: typeof defineTree;
  defineItem: typeof defineItem;
};
```

## Parameters

| Name                                              | Type                                                | Required | Default     | Description                                                                                                                                                                                                                                                         |
| ------------------------------------------------- | --------------------------------------------------- | -------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `contentFolder`                                   | `string`                                            | yes      |             | Directory, relative to the working directory, that every `directory` and `file` path is joined onto                                                                                                                                                                 |
| `mediaFolder`                                     | `string`                                            | yes      |             | Directory, relative to the working directory, serving media at the site root, such as `public`                                                                                                                                                                      |
| `siteUrl`                                         | `string`                                            | no       |             | The site's origin, such as `"https://example.com"`, that links in page Markdown and `llms.txt` are made absolute on. Required when a primitive declares `pages` or `page`, or `cli.build.llmsTxt` is on. See [Agent-ready content](https://www.qino.works/docs/guide/agent-ready-content) |
| `cli.check.localAssetReferences`                  | `boolean \| { exclude? }`                           | no       | `true`      | Whether `qino check` verifies that files referenced in content exist. See [Media](https://www.qino.works/docs/guide/cli#media)                                                                                                                                                            |
| `cli.check.localAssetReferences.exclude`          | `ReadonlyArray<string>`                             | no       | `[]`        | URL globs served by routes instead of `mediaFolder`, such as `/og/**`                                                                                                                                                                                               |
| `cli.build.types`                                 | `boolean`                                           | no       | `true`      | Whether `qino build` writes `qino/_generated/types.d.ts`. See [qino build](https://www.qino.works/docs/guide/cli#qino-build)                                                                                                                                                              |
| `cli.build.llmsTxt`                               | `boolean \| { template?, sections? }`               | no       | `false`     | Whether `qino build` writes `llms.txt`, `llms-full.txt` and `index.md` at the root of `mediaFolder`. See [llms.txt](https://www.qino.works/docs/guide/cli#llmstxt)                                                                                                                        |
| `cli.build.llmsTxt.template`                      | `string`                                            | no       | `"llms.md"` | The `llms.txt` template, relative to `contentFolder`                                                                                                                                                                                                                |
| `cli.build.llmsTxt.sections`                      | `boolean`                                           | no       | `false`     | Whether `qino build` also writes a section llms.txt per collection and tree that declares pages, and `llms.txt` links to them in place of their sections. See [Section llms.txt](https://www.qino.works/docs/guide/cli#section-llmstxt)                                                   |
| `cloud`                                           | `object`                                            | no       |             | Configures the cloud UI. When set, `qino build` writes `qino/_generated/config.json` and `qino check` verifies it. Requires schemas implementing [Standard JSON Schema](https://standardschema.dev/json-schema). See [Cloud](https://www.qino.works/docs/guide/cloud)                     |
| `cloud.publish.mode`                              | `"open_pull_request" \| "commit_to_default_branch"` | yes      |             | Whether publishing opens a pull request or commits to the default branch                                                                                                                                                                                            |
| `cloud.publish.reviewBeforePublish`               | `boolean \| { bypassIfAdmin? }`                     | yes      |             | Whether an approver signs off in qino before the author can publish. An object turns review on and configures it                                                                                                                                                    |
| `cloud.publish.reviewBeforePublish.bypassIfAdmin` | `boolean`                                           | no       | `false`     | Whether admins can publish before every entry is approved                                                                                                                                                                                                           |
| `cloud.publish.branchPrefix`                      | `string`                                            | no       | `"qino/"`   | Prefix of the branches the cloud UI opens. `open_pull_request` only                                                                                                                                                                                                 |
| `incrementalEntries`                              | `boolean`                                           | no       | `false`     | Whether a collection's `getEntries`, and `getPaginatedEntries` on a filtered or sorted view, keep entries between calls, rebuilding only those whose files changed. Meant for a dev server. See [Incremental entries](#incremental-entries)                         |

The config type is not exported; pass an object literal.

## Returns

An instance with three methods:

- [`defineCollection`](https://www.qino.works/docs/api/collection)
- [`defineTree`](https://www.qino.works/docs/api/tree)
- [`defineItem`](https://www.qino.works/docs/api/item)

The methods are closures, so destructuring them is fine:

```ts title="qino/index.ts"
export const { defineCollection, defineTree, defineItem } = initQino({
  contentFolder: "src/content",
  mediaFolder: "public",
});
```

Each instance carries a unique identity. Primitives from one instance cannot be related to primitives from another, and `qino lint` rejects a project that mixes instances.

## Incremental entries

A `getEntries` call, or a `getPaginatedEntries` call on a view that filters or sorts, builds every entry of the collection: its images, its relations, and the view. Parsed files are cached, but on a large collection the rest still takes seconds per call under `next dev`, which makes every promise slower. `incrementalEntries` keeps each view's entries between calls, and builds again only the ones whose files changed:

```ts title="qino/index.ts"
export default initQino({
  contentFolder: "src/content",
  mediaFolder: "public",
  incrementalEntries: process.env.NODE_ENV == "development",
});
```

- Each entry is kept with every file it was built from: its own file, its images, and each relation target it resolved, with the target's images, down to the resolve depth.
- Each call checks those files, with one sync stat per file, and builds again only the entries whose files changed. An edit shows up on the next call.
- A file read within 2 seconds of an edit is read again on every call until it's older, because some file systems record modification times only to the second or two.
- `augment`, `filter`, and `sort` still run on every call, over every entry, so a `filter` that reads the clock or an `augment` that reads other data stays fresh. A sync `augment` adds little. An async one adds a promise per entry.
- Entries are kept per collection instance and view, so the first call for a view on an instance still builds every entry.
- Other reads build their entries on every call, as without the option: `getEntry`, `getPaginatedEntries` on a view that neither filters nor sorts, and every tree and item getter.

With the option on:

- A reused entry skips its relation and media `parse` callbacks, as a cached file skips its schema transforms, so they don't run on every call. Read other data in `augment` instead.
- A lazy relation target, `() => collection`, must return the same collection every time.
- Entries that reference one target can hold different objects for it. Group them by the target's `_meta.filePath` or slug, not by object.
- Nested objects are shared between calls made one after another, not only between concurrent ones. Treat entries as read-only.

It's meant for dev. A production build prerenders its pages, and a content change ships in a new deploy. The checks block the event loop while they run, which is quick on a local disk but slower on a network drive or a Docker bind mount.

## Throws

- `siteUrl "<siteUrl>" must be an http(s) origin, such as "https://example.com".` A path after the host is rejected, but a trailing `/` is allowed and dropped.

Folder existence is checked by the CLI, not at creation.

## CLI expectations

The CLI loads `qino/index.ts` and requires the instance to be its default export. See [Project structure](https://www.qino.works/docs/guide/project-structure).

## See also

- [Project structure](https://www.qino.works/docs/guide/project-structure)
- [Errors](https://www.qino.works/docs/api/errors)
