The Ace console
Ace is the AdonisJS console. It is a set of commands run through node ace that do routine work: create controllers and models from templates, run migrations, install packages. It is the counterpart of Artisan in Laravel.
Listing commands
node ace listThe command prints all available commands grouped by topic: make, migration, db and others. The --help flag shows details of any command:
node ace make:controller --helpYou see the command's arguments and flags with descriptions.
Creating files
The make commands create files in the right folder with the right name:
node ace make:controller postsThe file app/controllers/posts_controller.ts appears with an empty PostsController class. File names in AdonisJS are written in snake_case — words joined with underscores.
| Command | What it creates |
|---|---|
make:controller posts | app/controllers/posts_controller.ts |
make:model Post | app/models/post.ts |
make:migration posts | a file in database/migrations/ |
make:validator post | app/validators/post.ts |
make:middleware log_requests | a file in app/middleware/ |
make:view posts/index | resources/views/posts/index.edge |
Installing packages
Official AdonisJS packages are installed with the add command. It installs the package through npm and configures it right away: creates a file in config/, adds variables to .env, registers a provider in adonisrc.ts.
node ace add @adonisjs/mailIf the package is already installed through npm, configure it with node ace configure @adonisjs/mail.
Your own command
You can write your own command too. Create it:
node ace make:command greetOpen the new file and add an argument and the run method:
// commands/greet.ts
import { BaseCommand, args } from '@adonisjs/core/ace'
export default class Greet extends BaseCommand {
static commandName = 'greet'
static description = 'Greet a user'
@args.string()
declare name: string
async run() {
this.logger.info(`Hello, ${this.name}!`)
}
}Now node ace greet Anna prints "Hello, Anna!" in the terminal. The commandName property sets the command name, and the @args.string() decorator declares an argument.
REPL
node ace repl opens an interactive console with the application loaded. It is handy for trying database queries without building pages.
Common mistake
make commands do not overwrite existing files: if posts_controller.ts already exists, Ace says so and creates nothing. Do not delete the file just to rerun the command — you will lose the code you wrote. If you need another file, give it another name.