Install CopyPatch v2

CopyPatch packages are published under the @copypatch npm scope. Install only the packages required for your client and server architecture.

Prerequisites

  • Runtime: Node.js >=20.0.0 (Node.js 24 LTS recommended)
  • Module Format: Pure ESM (ECMAScript Modules)
  • Peer Dependencies: React >=18.0.0 and React DOM >=18.0.0
  • Environment: Server-capable host application with same-origin routing

Package Ecosystem

Package Target Environment Description
@copypatch/core Universal (Browser & Server) Types, schema validation, string normalizers, and API constants.
@copypatch/react Browser (React) CopyPatchProvider, EditableText, React hooks, and lazy editor UI.
@copypatch/backend Node / Edge Server Embedded Web Request/Response API runtime, Argon2id auth, and CSRF protection.
@copypatch/storage-sqlite Node Server Transactional SQLite storage adapter with atomic compare-and-swap revisions.
@copypatch/storage-postgres Node Server Connection-pooled PostgreSQL storage adapter for distributed instances.
@copypatch/node Node Server & CLI Native Node HTTP, Express, Fastify, Hono middleware, and the copypatch CLI.
@copypatch/next Next.js App Router Same-origin route handlers, server component snapshot reader, and Next.js provider.

Installing Dependencies

Terminal (pnpm)
# Core & React Client
pnpm add @copypatch/core @copypatch/react

# Embedded Backend & SQLite Storage
pnpm add @copypatch/backend @copypatch/storage-sqlite

# Framework Adapters (Choose your host)
pnpm add @copypatch/next    # For Next.js App Router
pnpm add @copypatch/node    # For Astro, Express, Fastify, Hono, React Router
Terminal (npm)
npm install @copypatch/core @copypatch/react @copypatch/backend @copypatch/storage-sqlite @copypatch/next

CLI Scaffolding & Utility Commands

The @copypatch/node package includes the official copypatch CLI to scaffold configuration files, hash passphrases, and run migrations:

CLI Commands
# Interactive scaffolding (or provide explicit flags)
npx copypatch init --framework next --storage sqlite

# Test scaffolding without writing files
npx copypatch init --framework next --storage sqlite --dry-run

# Generate secure Argon2id passphrase hash
printf 'your-secure-passphrase' | npx copypatch hash --stdin

# Apply database schema migrations
npx copypatch migrate --storage sqlite

# Verify runtime configuration and health
npx copypatch doctor

CLI Command Reference

Command Flags Purpose
copypatch init --framework <next|astro|react-router|vite-node>
--storage <sqlite|postgres>
--dry-run, --cwd <dir>
Generates copypatch.config.ts, copypatch.env.example, and the matching route file. Safe to re-run; never overwrites conflicting files.
copypatch hash --stdin, --passphrase <str> Generates a cryptographically secure Argon2id hash. Using --stdin prevents exposing secrets in shell history.
copypatch migrate --storage <sqlite|postgres> Executes idempotent database schema migrations.
copypatch doctor None Inspects the local configuration, environment variables, and storage connectivity.
Note: The CopyPatch CLI intentionally does not have a serve command. CopyPatch is embedded into your application's existing HTTP server instead of running as a separate daemon.