You are viewing the legacy version of AdonisJS. Visit https://adonisjs.com for newer docs. This version will receive security patches until the end of 2021.

Ignitor

Ignitor is the package that powers bootstrapping of an AdonisJs application. In this guide, we learn about some features and functionalities offered by this package to manage our code.

Hooks

Ignitor provides a bunch of hooks that you can use to customize the application behavior. The hooks are registered inside start/hooks.js file. Feel free to create this file, if it is missing.

Let’s start with an example of register a view global after all the providers have been booted.

const { hooks } = require('@adonisjs/ignitor')

hooks.after.providersBooted(() => {
  const View = use('View')
  View.global('time', () => new Date().getTime())
})

Just like hooks.after, you can make use of hooks.before to hook into before something happens. Below is the list of available hooks.

Hook Description

providersRegistered

Before/after all providers have been registered

providersBooted

Before/after all providers are booted.

preloading

Before/after pre loading registered files.

httpServer

Before/after HTTP server has been started.

aceCommand

Before/after ace command is executed.

Preloading files

Ignitor also makes it easy to preload a bunch of files after HTTP server has been started. For this, you need to modify server.js file and call the following method.

new Ignitor(require('@adonisjs/fold'))
  .appRoot(__dirname)
  .preLoad('start/fire-zombies')
  .fireHttpServer()
  .catch(console.error)

The preLoad method takes a relative path from the application path or an absolute path to any .js file. To load multiple files, just call the preLoad method for multiple times.

new Ignitor(require('@adonisjs/fold'))
  .preLoad('')
  .preLoad('')

Ignitor methods

Below is the list of methods available on the ignitor instance.

appRoot(location)

Define absolute path to the application root.

ignitor
  .appRoot(__dirname)

appFile(location)

Relative path to the app file. By default start/app.js file is used.

ignitor
  .appFile('start/app.js')

loadCommands()

Instruct ignitor to load ace providers and commands. It is done when running an ace command. However, you can also load commands when starting the HTTP server.

ignitor
  .loadCommands()