How to use app-root-path

Comprehensive app-root-path code examples:

How to use app-root-path.resolve:

21
22
23
24
25
26
27
28
29
30
31
32
33
34
  return rootDir;
}());


appRoot.setPath(appRootDir);


const root = dir => appRoot.resolve(dir || '');


let serverConfig = {};


/**

How to use app-root-path.path:

14
15
16
17
18
19
20
21
22
23

const calculatedAppRoot = !!require.main ? path.dirname(require.main.filename) : (!!process.mainModule ? path.dirname(process.mainModule.filename) : process.cwd())

/// Determine root configuration folder
this._configFilePathRelative = opts.relativePath
this._configFilePathAppRoot = fs.existsSync(calculatedAppRoot) ? calculatedAppRoot : appRoot.path

/// include files that match this in their filename (including extension)
this._configSelectors = opts.configSelectors || ['config.js']
this._dataSelectors = opts.dataSelectors || ['.json']

How to use app-root-path.default:

27
28
29
30
31
32
33
34
35
36
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.URL = exports.API_KEY = exports.PUBLIC_ENV = exports.ROOT = void 0;
const app_root_path_1 = __importDefault(require("app-root-path"));
const dotenv = __importStar(require("dotenv"));
const ROOT = app_root_path_1.default.path;
exports.ROOT = ROOT;
const PUBLIC_ENV = dotenv.config({
    path: ROOT + '/public.env',
}).parsed;

How to use app-root-path.setPath:

4
5
6
7
8
9
10
11
12
13
use: root.require,
ROOT_PATH: root,
PUBLIC_PATH: root.setPath('/public'),
STORAGE_PATH: root.setPath('/storage'),
APP_PATH: root.setPath('/src/app'),
CLASS_PATH: root.setPath('/src/class'),
CONFIG_PATH: root.setPath('/src/config'),
DATA_PATH: root.setPath('/src/data'),
DB_PATH: root.setPath('/src/db'),
HELPER_PATH: root.setPath('/src/helpers'),