No more ugly path inside the require
.
const user = require('../../../database/user') // π what you have
// OR
const user = require('$db/user') // π no matter how deep you are
const product = require('/database/product') // π alias or pathing from application directory
Three simple steps to use it.
Install the package: npm install sexy-require --save
Include require('sexy-require')
once on the top of your main application file.
require('sexy-require')
const routers = require('/routers')
const api = require('$api')
...
Optional step. Path configuration can be defined in .paths
file on root directory of your project.
$db = /server/database
$api-v1 = /server/api/legacy
$api-v2 = /server/api/v2
Anywhere in your project you can get the defined shortcut paths:
const path = require(`sexy-require`)
console.log(path.$db) // -> '/full/path/to/app/server/database'
package.json
to .paths
config filesexy-require
too, previously it was not possible