Skip to content

CLI Reference

The EmDash CLI provides commands for managing an EmDash CMS instance — database setup, type generation, content CRUD, schema management, media, and more.

The CLI is included with the emdash package:

Terminal window
npm install emdash

Run commands with npx emdash or add scripts to package.json. The binary is also available as ec for brevity.

Commands that talk to a running EmDash instance (everything except init, seed, export-seed, and auth secret) resolve authentication in this order:

  1. --token flag — explicit token on the command line
  2. EMDASH_TOKEN env var
  3. Stored credentials from ~/.config/emdash/auth.json (saved by emdash login)
  4. Dev bypass — if the URL is localhost and no token is available, automatically authenticates via the dev bypass endpoint

Most commands accept --url (default http://localhost:4321) and --token flags. When targeting a local dev server, no token is needed.

These flags are available on all remote commands:

FlagAliasDescriptionDefault
--url-uEmDash instance URLhttp://localhost:4321
--token-tAuth tokenFrom env/stored creds
--jsonOutput as JSON (for piping)Auto-detected from TTY

When stdout is a TTY, the CLI pretty-prints results with consola. When piped or when --json is set, it outputs raw JSON to stdout — suitable for jq or other tools.

Initialize the database with core schema and optional template data.

Terminal window
npx emdash init [options]
OptionAliasDescriptionDefault
--database-dDatabase file path./data.db
--cwdWorking directoryCurrent directory
--force-fRe-run schema and seedfalse
  1. Reads emdash config from package.json
  2. Creates the database file if needed
  3. Runs core migrations (creates system tables)
  4. Runs template schema.sql if configured
  5. Runs template seed.sql if configured

Start the development server with automatic database setup.

Terminal window
npx emdash dev [options]
OptionAliasDescriptionDefault
--database-dDatabase file path./data.db
--types-tGenerate types from remote before startingfalse
--port-pDev server port4321
--cwdWorking directoryCurrent directory
Terminal window
# Start dev server
npx emdash dev
# Custom port
npx emdash dev --port 3000
# Generate types from remote before starting
npx emdash dev --types
  1. Checks for and runs pending database migrations
  2. If --types is set, generates TypeScript types from a remote instance (URL from EMDASH_URL env or emdash.url in package.json)
  3. Starts Astro dev server with EMDASH_DATABASE_URL set

Generate TypeScript types from a running EmDash instance’s schema.

Terminal window
npx emdash types [options]
OptionAliasDescriptionDefault
--url-uEmDash instance URLhttp://localhost:4321
--token-tAuth tokenFrom env/stored creds
--output-oOutput path for types.emdash/types.ts
--cwdWorking directoryCurrent directory
Terminal window
# Generate types from local dev server
npx emdash types
# Generate from remote instance
npx emdash types --url https://my-site.pages.dev
# Custom output path
npx emdash types --output src/types/emdash.ts
  1. Fetches the schema from the instance
  2. Generates TypeScript type definitions
  3. Writes types to the output file
  4. Writes schema.json alongside for reference

Log in to an EmDash instance using OAuth Device Flow.

Terminal window
npx emdash login [options]
OptionAliasDescriptionDefault
--url-uEmDash instance URLhttp://localhost:4321
  1. Discovers auth endpoints from the instance
  2. If localhost and no auth configured, uses dev bypass automatically
  3. Otherwise initiates OAuth Device Flow — displays a code and opens your browser
  4. Polls for authorization, then saves credentials to ~/.config/emdash/auth.json

Saved credentials are used automatically by all subsequent commands targeting the same instance.

Log out and remove stored credentials.

Terminal window
npx emdash logout [options]
OptionAliasDescriptionDefault
--url-uEmDash instance URLhttp://localhost:4321

Show the current authenticated user.

Terminal window
npx emdash whoami [options]
OptionAliasDescriptionDefault
--url-uEmDash instance URLhttp://localhost:4321
--token-tAuth tokenFrom env/stored creds
--jsonOutput as JSON

Displays email, name, role, auth method, and instance URL.

Manage content items. All subcommands use the remote API via EmDashClient.

Terminal window
npx emdash content list posts
npx emdash content list posts --status published --limit 10
OptionDescription
--statusFilter by status
--limitMaximum items
--cursorPagination cursor
Terminal window
npx emdash content get posts 01ABC123
npx emdash content get posts 01ABC123 --raw
OptionDescription
--rawReturn raw Portable Text (skip markdown conversion)

The response includes a _rev token — pass it to content update to prove you’ve seen what you’re overwriting.

Terminal window
npx emdash content create posts --data '{"title": "Hello"}'
npx emdash content create posts --file post.json --slug hello-world
cat post.json | npx emdash content create posts --stdin
OptionDescription
--dataJSON string with content data
--fileRead data from a JSON file
--stdinRead data from stdin
--slugContent slug
--statusInitial status (draft, published)

Provide data via exactly one of --data, --file, or --stdin.

Like a file editor that requires you to read before you write — you must provide the _rev token from a prior get to prove you’ve seen the current state. This prevents accidentally overwriting changes you haven’t seen.

Terminal window
# 1. Read the item, note the _rev
npx emdash content get posts 01ABC123
# 2. Update with the _rev from step 1
npx emdash content update posts 01ABC123 \
--rev MToyMDI2LTAyLTE0... \
--data '{"title": "Updated"}'
OptionDescription
--revRevision token from get (required)
--dataJSON string with content data
--fileRead data from a JSON file

If the item has changed since your get, the server returns 409 Conflict — re-read and try again.

Terminal window
npx emdash content delete posts 01ABC123

Soft-deletes the content item (moves to trash).

Terminal window
npx emdash content publish posts 01ABC123
Terminal window
npx emdash content unpublish posts 01ABC123
Terminal window
npx emdash content schedule posts 01ABC123 --at 2026-03-01T09:00:00Z
OptionDescription
--atISO 8601 datetime (required)
Terminal window
npx emdash content restore posts 01ABC123

Restores a trashed content item.

Manage collections and fields.

Terminal window
npx emdash schema list

Lists all collections.

Terminal window
npx emdash schema get posts

Shows a collection with all its fields.

Terminal window
npx emdash schema create articles --label Articles
npx emdash schema create articles --label Articles --label-singular Article --description "Blog articles"
OptionDescription
--labelCollection label (required)
--label-singularSingular label
--descriptionCollection description
Terminal window
npx emdash schema delete articles
npx emdash schema delete articles --force
OptionDescription
--forceSkip confirmation

Prompts for confirmation unless --force is set.

Terminal window
npx emdash schema add-field posts body --type portableText --label "Body Content"
npx emdash schema add-field posts featured --type boolean --required
OptionDescription
--typeField type: string, text, number, integer, boolean, datetime, image, reference, portableText, json (required)
--labelField label (defaults to field slug)
--requiredWhether the field is required
Terminal window
npx emdash schema remove-field posts featured

Manage media items.

Terminal window
npx emdash media list
npx emdash media list --mime image/png --limit 20
OptionDescription
--mimeFilter by MIME type
--limitNumber of items
--cursorPagination cursor
Terminal window
npx emdash media upload ./photo.jpg
npx emdash media upload ./photo.jpg --alt "A sunset" --caption "Taken in Bristol"
OptionDescription
--altAlt text
--captionCaption text
Terminal window
npx emdash media get 01MEDIA123
Terminal window
npx emdash media delete 01MEDIA123

Full-text search across content.

Terminal window
npx emdash search "hello world"
npx emdash search "hello" --collection posts --limit 5
OptionAliasDescription
--collection-cFilter by collection
--limit-lMaximum results

Manage taxonomies and terms.

Terminal window
npx emdash taxonomy list
Terminal window
npx emdash taxonomy terms categories
npx emdash taxonomy terms tags --limit 50
OptionAliasDescription
--limit-lMaximum terms
--cursorPagination cursor
Terminal window
npx emdash taxonomy add-term categories --name "Tech" --slug tech
npx emdash taxonomy add-term categories --name "Frontend" --parent 01PARENT123
OptionDescription
--nameTerm label (required)
--slugTerm slug (defaults to slugified name)
--parentParent term ID (for hierarchical taxonomies)

Manage navigation menus.

Terminal window
npx emdash menu list
Terminal window
npx emdash menu get primary

Returns the menu with all its items.

Apply a seed file to the database. This command works directly on a local SQLite file (no running server needed).

Terminal window
npx emdash seed [path] [options]
ArgumentDescriptionDefault
pathPath to seed file.emdash/seed.json
OptionAliasDescriptionDefault
--database-dDatabase file path./data.db
--cwdWorking directoryCurrent directory
--validateValidate only, don’t applyfalse
--no-contentSkip sample contentfalse
--on-conflictConflict handling: skip, update, errorskip
--uploads-dirDirectory for media uploads.emdash/uploads
--media-base-urlBase URL for media files/_emdash/api/media/file
--base-urlSite base URL (for absolute media URLs)

The command looks for seed files in this order:

  1. Positional argument (if provided)
  2. .emdash/seed.json (convention)
  3. Path from package.json emdash.seed field

Export database schema and content as a seed file. Works directly on a local SQLite file.

Terminal window
npx emdash export-seed [options] > seed.json
OptionAliasDescriptionDefault
--database-dDatabase file path./data.db
--cwdWorking directoryCurrent directory
--with-contentInclude content (all or comma-separated collections)
--no-prettyDisable JSON formattingfalse

The exported seed file includes:

  • Settings: Site title, tagline, social links
  • Collections: All collection definitions with fields
  • Taxonomies: Taxonomy definitions and terms
  • Menus: Navigation menus with items
  • Widget Areas: Widget areas and widgets
  • Content (if requested): Entries with $media references and $ref: syntax for portability

Generate a secure authentication secret for your deployment.

Terminal window
npx emdash auth secret

Outputs a random secret suitable for EMDASH_AUTH_SECRET.

TypeScript interfaces generated by emdash types:

// Generated by EmDash CLI
// Do not edit manually - run `emdash types` to regenerate
import type { PortableTextBlock } from "emdash";
export interface Post {
id: string;
title: string;
content: PortableTextBlock[];
publishedAt: Date | null;
}

Raw schema export for tooling:

{
"version": "a1b2c3d4",
"collections": [
{
"slug": "posts",
"label": "Posts",
"fields": [...]
}
]
}
VariableDescription
EMDASH_DATABASE_URLDatabase URL (set automatically by dev)
EMDASH_TOKENAuth token for remote operations
EMDASH_URLDefault remote URL for types and dev --types
EMDASH_AUTH_SECRETSecret for passkey authentication
EMDASH_PREVIEW_SECRETSecret for preview token generation
{
"scripts": {
"dev": "emdash dev",
"init": "emdash init",
"types": "emdash types",
"seed": "emdash seed",
"export-seed": "emdash export-seed",
"db:reset": "rm -f data.db && emdash init"
}
}
CodeDescription
0Success
1Error (configuration, network, database)