Skip to content

Commit 86f4052

Browse files
committed
Added resolve() method
1 parent 0041196 commit 86f4052

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ A helper function is also provided:
2626

2727
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.
2828

29+
Finally, you can also just resolve a module path:
30+
31+
``` js
32+
var myModulePath = require('app-root-path').resolve('/lib/my-module.js');
33+
```
34+
2935
## How It Works
3036

3137
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:

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
var path = require('path'),
22
appRootPath = path.resolve(__dirname, '..', '..');
33

4+
exports.resolve = function(pathToModule) {
5+
return path.join(appRootPath, pathToModule);
6+
};
7+
48
exports.require = function(moduleReqire) {
59
return function(pathToModule) {
610
return moduleReqire(exports.resolve(pathToModule));

0 commit comments

Comments
 (0)