Skip to content

Commit

Permalink
Added resolve() method
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Aug 7, 2014
1 parent 0041196 commit 86f4052
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,12 @@ A helper function is also provided:

This works by passing the current module's `require` method (each module has its *own* `require` method) to the `app-root-path` module, which then returns a wrapper for that method that prepends the application's root path to whatever path is passed to it.

Finally, you can also just resolve a module path:

``` js
var myModulePath = require('app-root-path').resolve('/lib/my-module.js');
```

## How It Works

This module works on the assumption that your application's root path is the parent of the `node_modules` directory. Here's almost all the module's logic:
Expand Down
4 changes: 4 additions & 0 deletions index.js
@@ -1,6 +1,10 @@
var path = require('path'),
appRootPath = path.resolve(__dirname, '..', '..');

exports.resolve = function(pathToModule) {
return path.join(appRootPath, pathToModule);
};

exports.require = function(moduleReqire) {
return function(pathToModule) {
return moduleReqire(exports.resolve(pathToModule));
Expand Down

0 comments on commit 86f4052

Please sign in to comment.