Commands
Complete reference of npm scripts and CLI commands
Overview
This page documents all available npm scripts and CLI commands for development, database management, routing, testing, and deployment.
Development Commands
Start Development Server
npm run devStarts the Next.js development server with:
- Turbopack for fast refresh
- Hot module replacement (HMR)
- Declarative routing watch mode (automatically rebuilds routes on page changes)
- Server runs on
http://localhost:3000
The dev command runs two processes concurrently: the Next.js dev server and the declarative routing watcher. Both will restart automatically when you make changes.
Build for Production
npm run buildCreates an optimized production build:
- Compiles TypeScript
- Bundles and minifies JavaScript/CSS
- Optimizes images and assets
- Generates static pages
- Uses Turbopack for faster builds
Run this before deploying or to test production behavior locally.
Start Production Server
npm run startStarts the production server after running npm run build. Used for testing production builds locally before deployment.
Database Commands
Push Schema Changes
npm run db:pushUse this for development. Pushes your schema changes directly to the database without creating migration files:
- Syncs
src/db/tables/*.tswith database - Fast iteration during development
- No migration history
- Can cause data loss if not careful
Use db:push in development only. Use db:generate and db:migrate for production deployments.
When to use:
- During active development
- After creating/modifying tables in
src/db/tables/ - When you want instant schema updates
Generate Migration
npm run db:generateGenerates SQL migration files from schema changes:
- Creates migration file in
src/db/migrations/ - Compares current schema with database
- Generates SQL statements for changes
- Safe for production use
When to use:
- Before deploying to staging/production
- When you want version-controlled schema changes
- To review SQL before applying
Run Migrations
npm run db:migrateApplies pending migrations to the database:
- Executes SQL files from
src/db/migrations/ - Tracks applied migrations
- Safe, reversible schema changes
When to use:
- Deploying to staging/production
- After pulling migration files from git
- Setting up a new environment
Database Studio
npm run db:studioOpens Drizzle Studio in your browser (http://localhost:4983):
- Visual database browser
- View and edit table data
- Run queries
- Inspect schema
When to use:
- Debugging data issues
- Manually editing records
- Exploring database structure
Drizzle Studio connects to your DATABASE_URL from .env.local. Make sure it's configured before running this command.
Routing Commands
Build Routes
npm run dr:buildBuilds declarative routing configuration:
- Scans
src/app/[locale]/for pages - Reads
page.info.tsfiles for metadata - Generates
src/routes/index.tswith type-safe routes - Creates route helpers (
PageName(),<PageName.Link />)
When to use:
- After creating new pages
- After modifying route metadata
- Before committing routing changes
Build Routes (Watch Mode)
npm run dr:build:watchContinuously watches for changes and rebuilds routes automatically:
- Monitors
src/app/[locale]/directory - Auto-rebuilds on page/metadata changes
- Runs automatically with
npm run dev
You typically don't need to run this manually as npm run dev includes it.
Type Checking & Linting
Type Check
npm run type-checkRuns TypeScript compiler in check mode:
- Validates all TypeScript files
- Reports type errors
- Does not emit JavaScript
- Checks entire project
When to use:
- Before committing code
- In CI/CD pipelines
- After major refactors
Lint Code
npm run lintRuns ESLint to check code quality:
- Identifies code style issues
- Reports potential bugs
- Enforces project conventions
- Includes Next.js-specific rules
When to use:
- Before committing code
- To find potential issues
- To enforce code standards
Run npm run lint before pushing code to ensure it passes CI checks.
Email Development
Email Dev Server
npm run email:devStarts the React Email development server:
- Preview email templates at
http://localhost:3001 - Hot reload for email changes
- Test email designs
- Inspect HTML output
When to use:
- Creating new email templates
- Designing email layouts
- Testing email rendering
- Previewing localized emails
Email templates are in src/emails/. The dev server watches this directory for changes.
Command Reference Table
| Command | Purpose | When to Use |
|---|---|---|
npm run dev | Start development server | Daily development |
npm run build | Build for production | Before deployment, testing |
npm run start | Start production server | After build, local testing |
npm run db:push | Push schema to database | Development schema changes |
npm run db:generate | Generate migrations | Before production deploy |
npm run db:migrate | Run migrations | Production deployments |
npm run db:studio | Open database studio | Data inspection/editing |
npm run dr:build | Build routes | After creating pages |
npm run dr:build:watch | Watch and build routes | Automatic with dev |
npm run type-check | Check TypeScript | Before commits, CI/CD |
npm run lint | Lint code | Before commits, CI/CD |
npm run email:dev | Email dev server | Email template development |
Development Workflow
Daily Development
# Start development
npm run dev
# In another terminal, if needed
npm run db:studioAfter Schema Changes
# During development
npm run db:push
# For production
npm run db:generate
npm run db:migrateBefore Committing
# Check types
npm run type-check
# Lint code
npm run lint
# Build to ensure no errors
npm run buildDeploying to Production
# Generate migrations
npm run db:generate
# Commit migrations
git add src/db/migrations
git commit -m "Add migration for <feature>"
# Build and test locally
npm run build
npm run start
# Deploy (Vercel, etc.)
git pushTroubleshooting
Dev Server Won't Start
- Check if port 3000 is already in use
- Verify
DATABASE_URLin.env.local - Delete
.nextfolder and restart:rm -rf .next && npm run dev
Database Push Fails
- Verify database is running
- Check
DATABASE_URLformat:postgresql://user:pass@host:port/db - Ensure database exists
- Check for conflicting schema changes
Type Errors After Route Changes
- Run
npm run dr:buildto regenerate routes - Restart TypeScript server in VS Code (Cmd/Ctrl + Shift + P → "Restart TypeScript Server")
Build Fails
- Run
npm run type-checkto see type errors - Run
npm run lintto see linting errors - Check for missing environment variables
- Clear
.nextfolder:rm -rf .next
Next Steps
- Best Practices - Learn development conventions
- AI Agents - Set up AI coding assistants
- Templates - Step-by-step task guides