This package is a wrapper around node native require function that resolved your packages from your application root, your application root is where your package.json file lives.
Installation is easy just copy and past the command in your terminal, assuming your terminal is pointing to your project root the package manager will handle the rest.
npm i underscore-require --save
After installation you only need to require the module once in your bootstrap process. This would be the main entry point of your application.
require('underscore-require');
When you run your application underscore require will be added to the global application namespace, allowing you to access it from any where in your application this is a neat way to eliminate the slashes we normally used.
Using this module is simple just refer to underscore require it take one argument the path you want to load that's it, remember underscore require will start looking from the file from the application root.
const module = _require('/');
This will default to loading index.js because no file name was given.
Loading a user model from the app directory domain, bellow you will see that we are going from app/model/UserModel, the app directory is located in the root so it will be resolved.
// UserModel.js
const Model = _require('app/model/BaseModel');
class UserModel extends Model{
// do what you want
}
Working with class
// UserController.js
const UserModel = _require('app/model/UserModel');
const user = new UserModel();