npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@better-auth-cloudflare/cli

v0.1.17

Published

CLI to generate Better Auth Cloudflare projects (Hono or OpenNext.js)

Downloads

312

Readme

@better-auth-cloudflare/cli

NPM Version NPM Downloads License: MIT

Part of the Better Auth Cloudflare ecosystem - A complete authentication solution for Cloudflare Workers with Better Auth, featuring ready-to-use templates and integrations.

Generate a Better Auth Cloudflare project with D1, KV, R2, or Hyperdrive. This CLI tool provides scaffolding for both Hono and Next.js (OpenNext.js) applications with automatic Cloudflare resource setup.

Note: The generate command configures one primary database (D1, Postgres via Hyperdrive, or MySQL via Hyperdrive). You can add additional database connections manually after project creation.

What This CLI Replaces

The generate command eliminates manual project setup:

🏗️ Creates complete Hono or Next.js projects with pre-configured auth (more types coming)

  • Sets up TypeScript configs, package.json scripts, file structure, and API routes
  • Creates database adapters for D1, Postgres, or MySQL

☁️ Handles Cloudflare resource creation:

  • Runs wrangler d1/kv/r2 create commands and configures wrangler.toml
  • Sets up Hyperdrive connections and auth integrations

📦 Runs initial setup: @better-auth/cli generate, drizzle-kit generate, and optionally applies migrations

🚀 Deploys to Cloudflare Workers when resources are set up (automatic in non-interactive mode, prompted in interactive mode)

The migrate command streamlines schema updates:

🔄 Handles the workflow when you modify auth configuration: generates auth schema, creates Drizzle migrations, and optionally applies them

Quick Start

Check version and get help:

npx @better-auth-cloudflare/cli --version    # Show version
npx @better-auth-cloudflare/cli -v           # Show version (short)
npx @better-auth-cloudflare/cli version      # Show version (command)
npx @better-auth-cloudflare/cli              # Show help with version

Interactive mode (asks questions):

npx @better-auth-cloudflare/cli generate

Non-interactive mode (use arguments):

# Simple D1 app with KV (ready to run)
npx @better-auth-cloudflare/cli generate \
  --app-name=my-auth-app \
  --template=hono \
  --database=d1 \
  --kv=true \
  --r2=false \
  --apply-migrations=dev

Migration workflow:

npx @better-auth-cloudflare/cli migrate              # Interactive
npx @better-auth-cloudflare/cli migrate --migrate-target=dev  # Non-interactive

The migrate command automatically detects your database configuration from wrangler.toml. It supports:

  • D1 databases: Offers migration options (dev/remote)
  • Hyperdrive databases: Shows informational message
  • Multiple databases: Prompts you to choose which D1 database to migrate

Arguments

--app-name=<name>              Project name (default: my-app)
--template=<template>          hono | nextjs (default: hono)
--database=<db>                d1 | hyperdrive-postgres | hyperdrive-mysql (default: d1)
--geolocation=<bool>           Enable geolocation tracking (default: true)
--kv=<bool>                    Use KV as secondary storage for Better Auth (default: true)
--r2=<bool>                    Enable R2 to extend Better Auth with user file storage (default: false)

KV Integration: Provides secondary storage for Better Auth sessions, rate limiting, and other features. See Better Auth secondary storage documentation.

R2 Integration: Enables file upload and management capabilities. See R2 setup guide for detailed configuration and usage.

Database-specific arguments

--d1-name=<name>               D1 database name (default: <app-name>-db)
--d1-binding=<binding>         D1 binding name (default: DATABASE)
--hd-name=<name>               Hyperdrive instance name (default: <app-name>-hyperdrive)
--hd-binding=<binding>         Hyperdrive binding name (default: HYPERDRIVE)
--hd-connection-string=<url>   Database connection string (required for hyperdrive)

Storage arguments

--kv-binding=<binding>         KV binding name (default: KV)
--kv-namespace-name=<name>     KV namespace name (default: <app-name>-kv)
--r2-binding=<binding>         R2 binding name (default: R2_BUCKET)
--r2-bucket-name=<name>        R2 bucket name (default: <app-name>-files)

Cloudflare account arguments

--account-id=<id>              Cloudflare account ID (only required if you have multiple accounts)
--skip-cloudflare-setup=<bool> Skip Cloudflare resource creation and deployment (default: false)
--apply-migrations=<choice>    Apply D1 migrations: dev | prod | skip (default: skip)

Migrate command arguments

--migrate-target=<target>      For migrate command: dev | remote | skip (default: skip)

Examples

Create a Hono app with D1 database:

npx @better-auth-cloudflare/cli generate --app-name=my-hono-app --template=hono --database=d1

Create a Next.js app with PostgreSQL via Hyperdrive:

npx @better-auth-cloudflare/cli generate --app-name=my-next-app --template=nextjs \
  --database=hyperdrive-postgres --hd-connection-string=postgres://user:pass@host:5432/db

Create app without KV or R2:

npx @better-auth-cloudflare/cli generate --app-name=minimal-app --kv=false --r2=false

Create and deploy in one command (default behavior):

npx @better-auth-cloudflare/cli generate --app-name=my-app
# Creates resources, runs migrations, and deploys automatically

Skip Cloudflare setup and deployment (useful for CI/CD):

npx @better-auth-cloudflare/cli generate --app-name=ci-app --skip-cloudflare-setup=true
# Only generates project files, no Cloudflare resources or deployment

Specify account ID for non-interactive mode:

npx @better-auth-cloudflare/cli generate --app-name=prod-app --account-id=your-account-id

Apply migrations automatically in non-interactive mode:

npx @better-auth-cloudflare/cli generate --app-name=auto-app --apply-migrations=dev

Run migration workflow interactively:

npx @better-auth-cloudflare/cli migrate

Run migration workflow with non-interactive target:

npx @better-auth-cloudflare/cli migrate --migrate-target=dev

Creates a new Better Auth Cloudflare project from Hono or OpenNext.js templates, optionally creating Cloudflare D1, KV, R2, or Hyperdrive resources for you. The migrate command runs auth:update, db:generate, and optionally db:migrate.

Related

License

MIT

Contributing

Contributions are welcome! Whether it's bug fixes, feature additions, or documentation improvements, we appreciate your help in making this project better. For major changes or new features, please open an issue first to discuss what you would like to change.