Thanks to visit codestin.com
Credit goes to github.com

Skip to content

qqpann/notcms

Repository files navigation

NotCMS logo

NotCMS

Website · Dashboard · Templates · Blog

NotCMS makes it easy to create a CMS, from Notion. It provides a type-safe TypeScript SDK to interact with Notion databases as your content backend.

npm package Downloads Issues DeepWiki

Key Features

  • 🛡️ Type Safety: Fully typed queries and responses using TypeScript
  • 🎯 Simple API: Clean and intuitive API for fetching content
  • 📝 Notion as Backend: Use Notion's user-friendly editor for content creation
  • 🔄 Framework Agnostic: Works with any JavaScript framework (Next.js, React, Vue, etc.)
  • 🛠️ CLI Tools: Includes notcms-kit for easy project setup and schema management

Getting Started

Installation

npm install notcms

Usage

0. Set Up Environment Variables

Create a .env file in your project root:

NOTCMS_SECRET_KEY=your_secret_key
NOTCMS_WORKSPACE_ID=your_workspace_id

You can get these values from the NotCMS Dashboard.

1. Initialize a Project

NotCMS Kit provides command-line tools to streamline your workflow. You can use it directly with npx:

npx notcms-kit init

This will create a notcms.config.json file in your project root.

2. Define Your Schema

The easiest way to define your schema is to use NotCMS Kit:

npx notcms-kit pull

This will automatically fetch your database schema from Notion and generate a TypeScript schema file.

For reference, the generated schema will look something like this:

// src/notcms/schema.ts
import { Client, Schema } from "notcms";

export const schema = {
  blog: {
    id: "your_notion_database_id",
    properties: {
      title: "title",
      description: "rich_text",
      published: "checkbox",
      thumbnails: "files",
      // Run notcms-kit pull again when properties are updated
    },
  },
} satisfies Schema;

export const nc = new Client({ schema });

3. Query Your Content

import { nc } from "./notcms/schema";

// List all blog posts
const [pages] = await nc.query.blog.list();

// Get a specific blog post
const [page] = await nc.query.blog.get("page_id");

// Handle errors
const [data, error] = await nc.query.blog.list();
if (error) {
  console.error("Failed to fetch blog posts:", error);
}

Examples and Templates

Check out these examples to get started quickly:

Troubleshooting

Authentication Errors

If you see errors like "secretKey is required" or "workspaceId is required", make sure:

  1. Your environment variables are correctly set
  2. You're using the correct variable names (NOTCMS_SECRET_KEY and NOTCMS_WORKSPACE_ID)
  3. Your environment variables are being loaded properly

Schema Errors

If you encounter schema-related errors:

  1. Make sure your Notion database IDs are correct
  2. Verify that the property types match what's in your Notion database
  3. Try running npx notcms-kit pull to regenerate your schema

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

This project is organized as a monorepo with multiple packages:

See individual directories for specific license details.

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages