sultan99 / sexy-require

πŸ’ƒπŸ» No more ugly path.
MIT License
39 stars 1 forks source link

πŸ’ƒπŸ» Sexy require v 1.1

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

Getting started

Three simple steps to use it.

  1. Install the package: npm install sexy-require --save

  2. Include require('sexy-require') once on the top of your main application file.

    require('sexy-require')
    const routers = require('/routers')
    const api = require('$api')
    ...
  3. 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

List of paths

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'

Changelog

v 1.1

v 0.1