CLI Commands
fastify-admin ships with a CLI available as npx fastify-admin <command> once the package is installed.
The CLI automatically loads .env from your current working directory, so no extra setup is needed.
Project Setup
init
npx fastify-admin initScaffolds starter files in your project:
.env— database and auth config templatemikro-orm.config.ts— ORM config importing the built-in entitiessrc/entities/post.entity.ts— example entitysrc/views/post.view.ts— example EntityViewsrc/index.ts— example Fastify server entry
Safe to run multiple times — existing files are never overwritten.
generate:resource
npx fastify-admin generate:resource ProductScaffolds a new entity + EntityView pair:
src/entities/product.entity.ts— MikroORM entity withid,name,createdAtsrc/views/product.view.ts—ProductViewextendingEntityViewwith sensible defaults
After generating, register the view in your server:
import { ProductView } from './views/product.view.js'
await app.register(fastifyAdmin, { orm, views: { product: new ProductView(), },})User Management
create-admin
npx fastify-admin create-adminCreates a new user and assigns them the Admin role. Prompts interactively for email, username, full name, and password.
reset-password
npx fastify-admin reset-passwordResets the password for an existing user. Prompts for the user’s email and new password (with confirmation).
Migrations
migrate:up
npx fastify-admin migrate:upApplies all pending migrations. Run this after installing the package to set up the admin tables.
migrate:down
npx fastify-admin migrate:downRolls back the last applied migration.
migrate:create
npx fastify-admin migrate:create [name]Creates a new migration file based on current entity changes.
schema:update
npx fastify-admin schema:updateSyncs the database schema directly without creating a migration. Development only — use migrate:up in production.
Environment Variables
The CLI reads database config from env vars (or .env in your project root):
| Variable | Default | Description |
|---|---|---|
DATABASE_URL | — | Full connection URL (overrides all below) |
DB_NAME | fastifyadmin | Database name |
DB_HOST | localhost | Database host |
DB_PORT | 5432 | Database port |
DB_USER | postgres | Database user |
DB_PASSWORD | password | Database password |
Monorepo / Contributing
If you’re working in the fastify-admin monorepo itself, use the pnpm scripts instead:
pnpm create-adminpnpm reset-passwordpnpm migration:createpnpm migration:uppnpm migration:downSee Contributing for full monorepo setup.