Skip to main content

Basic Setup

To start using NotCMS, you need to initialize a client with your schema and credentials:
import { Client } from 'notcms';
import { schema } from './notcms/schema';

const nc = new Client({
  schema,
  apiKey: process.env.NOTCMS_SECRET_KEY,
  workspaceId: process.env.NOTCMS_WORKSPACE_ID
});

Prerequisites

Before initializing the client, ensure you have:
  1. Generated schema - Run npx notcms-kit init to generate for the first time or npx notcms-kit pull to update your schema
  2. Environment variables - Set up your API credentials
  3. Installed NotCMS - Add notcms to your project dependencies

Environment Variables

Required Variables

NOTCMS_SECRET_KEY=your-secret-key
NOTCMS_WORKSPACE_ID=your-workspace-id

Loading Environment Variables

  • Next.js
  • Node.js
  • Vite
// Next.js loads .env automatically
import { Client } from 'notcms';

Framework-Specific Setup

Next.js App Router

// app/lib/notcms.ts
import { Client } from 'notcms';
import { schema } from '@/notcms/schema';

// Server-only client
export const nc = new Client({
  schema,
  apiKey: process.env.NOTCMS_SECRET_KEY!,
  workspaceId: process.env.NOTCMS_WORKSPACE_ID!
});

Remix

// app/lib/notcms.server.ts
import { Client } from 'notcms';
import { schema } from '~/notcms/schema';

// Mark as server-only with .server.ts extension
export const nc = new Client({
  schema,
  apiKey: process.env.NOTCMS_SECRET_KEY!,
  workspaceId: process.env.NOTCMS_WORKSPACE_ID!
});

SvelteKit

// src/lib/notcms.ts
import { Client } from 'notcms';
import { schema } from '../notcms/schema';
import { 
  NOTCMS_SECRET_KEY, 
  NOTCMS_WORKSPACE_ID 
} from '$env/static/private';

export const nc = new Client({
  schema,
  apiKey: NOTCMS_SECRET_KEY,
  workspaceId: NOTCMS_WORKSPACE_ID
});

Troubleshooting

Common Issues

  • Check .env file exists in project root
  • Ensure you’re using a loader like dotenv
  • Verify variable names match exactly
  • Verify NOTCMS_SECRET_KEY is correct
  • Check NOTCMS_WORKSPACE_ID matches your workspace
  • Ensure API key has necessary permissions
  • Run npx notcms-kit pull to generate schema
  • Check import path is correct
  • Ensure schema file exports correctly
  • Update to latest NotCMS version
  • Regenerate schema with npx notcms-kit pull
  • Check TypeScript version compatibility

Next Steps

Once your client is initialized, you can:
I