Skip to content

AdonisJS Commands

A comprehensive guide to AdonisJS CLI commands used in Jubiloop development.

Ace CLI

AdonisJS uses the Ace CLI for various development tasks. All commands are run from the apps/server directory.

bash
cd apps/server
node ace <command>

Development Commands

Starting the Server

bash
# Start development server with HMR
node ace serve --hmr

# Start with specific port
node ace serve --port=4000

# Start with debugging
node ace serve --node-args="--inspect"

Building for Production

bash
# Build the application
node ace build

# Build with production flag
node ace build --production

# Start production server
node bin/server.js

Database Commands

Migrations

bash
# Run pending migrations
node ace migration:run

# Rollback migrations
node ace migration:rollback

# Rollback specific batch
node ace migration:rollback --batch=2

# Rollback all migrations
node ace migration:rollback --batch=0

# Check migration status
node ace migration:status

# Preview migration SQL
node ace migration:run --dry-run

# Create new migration
node ace make:migration create_users_table

# Create migration for existing table
node ace make:migration add_avatar_to_users --table=users

Seeders

bash
# Run all seeders
node ace db:seed

# Run specific seeder
node ace db:seed --files="./database/seeders/user_seeder.ts"

# Create new seeder
node ace make:seeder user

# Create seeder in subdirectory
node ace make:seeder demo/demo_users

Database Management

bash
# Wipe database (drop all tables)
node ace db:wipe

# Wipe and migrate fresh
node ace migration:fresh

# Fresh migration with seeders
node ace migration:fresh --seed

Generators

Models

bash
# Create a model
node ace make:model User

# Model with migration
node ace make:model Event -m

# Model with controller
node ace make:model Organization -c

# Model with factory
node ace make:model Product -f

# All options
node ace make:model Post -mcf

Controllers

bash
# Create a controller
node ace make:controller users

# Resource controller (CRUD)
node ace make:controller events --resource

# API controller (no view methods)
node ace make:controller api/events --api

# Singular resource
node ace make:controller profile --singular

Validators

bash
# Create a validator
node ace make:validator create_user

# Validator in subdirectory
node ace make:validator auth/register

Middleware

bash
# Create middleware
node ace make:middleware auth

# Create in subdirectory
node ace make:middleware admin/verify_role

Services & Providers

bash
# Create a service
node ace make:service user_service

# Create a provider
node ace make:provider app_provider

Events & Listeners

bash
# Create an event
node ace make:event user_registered

# Create a listener
node ace make:listener send_welcome_email

# Create prldfile
node ace make:prldfile start/events

Mails

bash
# Create a mail class
node ace make:mail welcome_email

# Create with markdown view
node ace make:mail promotional --markdown

Authentication Commands

Setup Auth

bash
# Configure authentication
node ace configure @adonisjs/auth

# Generate auth scaffolding
node ace auth:scaffold

REPL & Testing

REPL (Interactive Console)

bash
# Start REPL
node ace repl

# In REPL, you can:
# > const user = await models.user.find(1)
# > await user.load('events')

Testing

bash
# Run all tests
node ace test

# Run specific test file
node ace test users.spec.ts

# Run tests matching pattern
node ace test --grep="User"

# Run with coverage
node ace test --coverage

# Watch mode
node ace test --watch

List & Help

Available Commands

bash
# List all commands
node ace list

# List make commands
node ace list make

# Get help for specific command
node ace migration:run --help

Custom Commands

Creating Custom Commands

bash
# Create a command
node ace make:command greet_user

# Command with custom signature
node ace make:command send_newsletter

Command Structure

typescript
import { BaseCommand } from '@adonisjs/core/ace'
import { CommandOptions } from '@adonisjs/core/types/ace'

export default class GreetUser extends BaseCommand {
  static commandName = 'greet:user'
  static description = 'Greet a user by name'

  static options: CommandOptions = {
    startApp: true, // Start the application
  }

  async run() {
    const name = await this.prompt.ask('Enter your name')
    this.logger.info(`Hello ${name}!`)
  }
}

Environment Commands

Configuration

bash
# Generate app key
node ace generate:key

# Validate environment variables
node ace env:validate

Package Management

Installing Packages

bash
# Configure a package
node ace configure @adonisjs/lucid

# Install and configure
npm install @adonisjs/redis
node ace configure @adonisjs/redis

Development Workflow

Common Sequences

Setting up a new feature:

bash
# 1. Create migration
node ace make:migration create_posts_table

# 2. Run migration
node ace migration:run

# 3. Create model
node ace make:model Post

# 4. Create controller
node ace make:controller posts --resource

# 5. Create validator
node ace make:validator create_post

Resetting database:

bash
# Drop all tables and re-run migrations
node ace migration:fresh

# With seeders
node ace migration:fresh --seed

Debugging:

bash
# Start with Node debugging
node ace serve --node-args="--inspect"

# Use REPL for testing
node ace repl

Tips & Tricks

Aliases

Add to your shell profile:

bash
alias ace="node ace"
alias serve="node ace serve --hmr"
alias migrate="node ace migration:run"
alias seed="node ace db:seed"

Common Patterns

  1. Always use migrations for schema changes
  2. Create validators for user input
  3. Use seeders for demo data
  4. Run tests before committing
  5. Use REPL for quick debugging

Troubleshooting

Command not found:

  • Ensure you're in apps/server directory
  • Check if @adonisjs/core is installed

Migration errors:

  • Check database connection
  • Verify migration syntax
  • Use --dry-run to debug

Build errors:

  • Clear build cache: rm -rf build
  • Check TypeScript errors
  • Verify dependencies

Built with ❤️ by the Jubiloop team