1.1.1 • Published 6 years ago

underscore-require v1.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Underscore Require

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.

Install

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');

How does it work?

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.

How to use this package?

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.

Looking at some simple example

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();
1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago