app-root-path
Version:
Determine an app's root path from anywhere inside the app
30 lines (23 loc) • 616 B
JavaScript
module.exports = function(dirname) {
var path = require('path');
var resolve = require('./resolve.js');
var appRootPath = resolve(dirname);
var publicInterface = {
resolve: function(pathToModule) {
return path.join(appRootPath, pathToModule);
},
require: function(pathToModule) {
return require(publicInterface.resolve(pathToModule));
},
toString: function() {
return appRootPath;
},
setPath: function(explicitlySetPath) {
appRootPath = path.resolve(explicitlySetPath);
publicInterface.path = appRootPath;
},
path: appRootPath
};
return publicInterface;
};
;