const Helpers = use('Helpers')
const storagePath = Helpers.storagePath()
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.
The Helpers Provider gives a handful of convenient methods to get absolute paths to certain directories of your application. It is helpful for the 3rd party Service providers since relying on relative paths is not very useful.
Anywhere inside your application, you can make use of Helper’s provider to get paths to different directories.
const Helpers = use('Helpers')
const storagePath = Helpers.storagePath()
Below is the list of available methods on the Helpers provider.
Returns path to the public directory or path to a file inside the directory.
const publicPath = Helpers.publicPath()
// or
const cssFile = Helpers.publicPath('style.css')
Returns path to the config directory or path to a file inside the directory.
It is recommended to make use of the Config Provider to read the values from the config files. |
const configPath = Helpers.configPath()
// or
const appConfig = Helpers.configPath('app.js')
Returns path to the storage directory or path to a file inside the directory.
const storagePath = Helpers.storagePath()
// or
const logs = Helpers.storagePath('logs.json')
Returns path to the resources directory or path to a file inside the directory.
const resourcesPath = Helpers.resourcesPath()
// or
const appSass = Helpers.resourcesPath('assets/sass/app.scss')
Returns path to the migrations directory or path to a file inside the directory.
const migrationsPath = Helpers.migrationsPath()
// or
const UserSchema = Helpers.migrationsPath('UserSchema.js')
Returns path to the seeds directory or path to a file inside the directory.
const seedsPath = Helpers.seedsPath()
// or
const DatabaseSeed = Helpers.seedsPath('Database.js')
Returns path to the database directory or path to a file inside the directory.
const databasePath = Helpers.databasePath()
// or
const factoryFile = Helpers.databasePath('factory.js')
Returns path to the views directory or path to a file inside the directory.
const viewsPath = Helpers.viewsPath()
// or
const welcomeView = Helpers.viewsPath('welcome.njk')
Returns the namespace mapped to the app
directory inside package.json
file.
const namespace = Helpers.appNameSpace()
const UsersController = use(`${namespace}/Http/Controllers/UsersController`)
Returns complete namespace for a file inside a given directory.
const httpListener = Helpers.makeNameSpace('Listeners', 'Http')
// returns App/Listeners/Http.js
Returns whether the process was started as the ace command or not.
Helpers.isAceCommand()