Install CopyPatch v3

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 and React DOM >=18 <20
  • Environment: Server-capable host application with same-origin routing

Package Ecosystem

PackageTarget EnvironmentDescription
@copypatch/coreUniversal (Browser & Server)Types, schema validation, string normalizers, and API constants.
@copypatch/reactBrowser (React)CopyPatchProvider, EditableText, React hooks, and lazy editor UI.
@copypatch/backendNode ServerEmbedded Web Request/Response API runtime, Argon2id auth, and CSRF protection.
@copypatch/storage-sqliteNode ServerTransactional SQLite storage adapter with atomic compare-and-swap revisions.
@copypatch/storage-postgresNode ServerConnection-pooled PostgreSQL storage adapter for distributed instances.
@copypatch/nodeNode Server & CLINative Node HTTP, Express, Fastify, Hono middleware, and the copypatch CLI.
@copypatch/nextNext.js App RouterSame-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/node @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

CommandFlagsPurpose
copypatch init–framework <next|astro|react-router|vite-node>
–storage <sqlite|postgres>
–dry-run, –cwd <dir>
Generates the configuration and route files, adds their direct dependencies to the host package.json, and prints the detected install command without running it. 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 doctorNoneInspects the generated configuration and required CopyPatch environment variables.

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.