From 86f4052f09f7ffbc2bca5a2dcbe9d98ca8341d53 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Thu, 7 Aug 2014 11:38:42 -0400 Subject: [PATCH] Added `resolve()` method --- README.md | 6 ++++++ index.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 31a6b3b..891eaea 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/index.js b/index.js index c1a37c3..c3a20a5 100644 --- a/index.js +++ b/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));