const Helpers = use('Helpers')
const welcomeView = Helpers.viewsPath('welcome.edge')
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 AdonisJs Helpers Provider enables a number of convenient methods to supercharge your application.
Many of these methods can be used to retrieve absolute paths to specific directories within your application.
From anywhere within your application, simply pull in the Helpers Provider and use it to retrieve paths to your different directories:
const Helpers = use('Helpers')
const welcomeView = Helpers.viewsPath('welcome.edge')
Below is the list of path related helpers available via the Helpers Provider.
Returns path to the public directory or file inside the directory:
const publicPath = Helpers.publicPath()
// or
const cssFile = Helpers.publicPath('style.css')
Returns path to the config directory or file inside the directory:
const configPath = Helpers.configPath()
// or
const appConfig = Helpers.configPath('app.js')
Use the Config Provider to read config file values. |
Returns path to the resources directory or file inside the directory:
const resourcesPath = Helpers.resourcesPath()
// or
const appSass = Helpers.resourcesPath('assets/sass/app.scss')
Returns path to the migrations directory or file inside the directory:
const migrationsPath = Helpers.migrationsPath()
// or
const UserSchema = Helpers.migrationsPath('UserSchema.js')
Returns path to the seeds directory or file inside the directory:
const seedsPath = Helpers.seedsPath()
// or
const DatabaseSeed = Helpers.seedsPath('Database.js')
Returns path to the database directory or file inside the directory:
const databasePath = Helpers.databasePath()
// or
const factoryFile = Helpers.databasePath('factory.js')
Returns path to the views directory or file inside the directory:
const viewsPath = Helpers.viewsPath()
// or
const welcomeView = Helpers.viewsPath('welcome.edge')
Returns path to the tmp directory or file inside the directory:
const tmpPath = Helpers.tmpPath()
// or
const resized = Helpers.tmpPath('resized.jpg')
Below is the list of other helpers available via the Helpers Provider.
Returns promisified callback functions:
const exists = Helpers.promisify(require('fs').exists)
const isExist = await exists(Helpers.tmpPath('image.jpg'))
// or
const fs = Helpers.promisify(require('fs'))
await fs.unlink(Helpers.tmpPath('image.jpg'))
Returns whether the process was started as the ace command or not:
Helpers.isAceCommand()