Skip to main content
The REPL module provides an interactive Read-Eval-Print Loop for AdonisJS applications, allowing you to interact with your application in real-time through the command line.

Starting the REPL

You can start the REPL using the repl command:
node ace repl
This will start an interactive Node.js REPL session with your AdonisJS application context loaded.

Features

The AdonisJS REPL provides several powerful features:
  • Application Context: Access your application instance, container, and all registered services
  • Auto-completion: Tab completion for methods and properties
  • Helper Methods: Built-in helpers for common tasks
  • Module Access: Import and test modules directly

Accessing Application Services

The REPL automatically makes several services available:
// Access the application instance
app

// Access the container
container

// Access registered services
logger.info('Hello from REPL')
router.toJSON()
config.get('app')

Using the REPL for Development

Testing Models and Queries

// Import your models
const User = await import('#models/user')

// Test queries
const users = await User.all()
console.log(users)

Testing Services

// Access container services
const hash = await container.make('hash')
const hashed = await hash.make('secret')
console.log(hashed)

Debugging Configuration

// Check configuration values
config.get('database')
config.get('app.appKey')

// Test environment variables
env.get('NODE_ENV')

REPL Commands

The REPL supports special commands:
.break
command
Exit a multi-line expression
.clear
command
Clear the REPL context
.exit
command
Exit the REPL session
.help
command
Show available commands
.load
command
Load a JavaScript file into the session
.save
command
Save the session to a file

Custom REPL Bindings

You can extend the REPL with custom bindings using a service provider:
import { ReplBinding } from '@adonisjs/core/repl'

export default class ReplProvider {
  constructor(protected app: ApplicationService) {}

  async ready() {
    this.app.container.withBindings(['repl'], (repl) => {
      repl.addMethod(
        'loadUser',
        async (id: number) => {
          const User = await import('#models/user')
          return User.find(id)
        },
        {
          description: 'Load a user by ID'
        }
      )
    })
  }
}

Module Re-exports

The REPL module re-exports all functionality from @adonisjs/repl:
export * from '@adonisjs/repl'
The REPL is built on top of Node.js’s native REPL module with AdonisJS-specific enhancements.

Best Practices

The REPL is perfect for quickly testing code snippets, queries, or services without writing test files.
The REPL is a development tool and should not be used in production environments.
Use dynamic imports to load modules on-demand rather than loading everything at startup.

See Also