apphome

A helper to require module relative to project root "APP_HOME" instead of current module directory.

npm install apphome
4 downloads in the last week
6 downloads in the last month

apphome.js

It is not uncommon to require modules residing in other directories from deep inside another directory, for example,

require('../../dir1/module1.js');
require('../../../dir2/module2.js');

Keeping track of relative require becomes a maintenance nightmare when we have a bunch of these and many directories.

apphome.js attempts to make relative require a little bit easier to maintain. It is a simple module that does only one thing - translate the given path relative to a known starting point.

install

To install the latest official version, use NPM:

npm install apphome

usage

apphome.js uses the environment variable APP_HOME to determine the root of the project. If APP_HOME is not set, it falls back to current working directory (as reported by process.cwd()).

var apphome = require('apphome');
var moda = require(apphome('moda'));
var modc = require(apphome('moda/modb/modc'));

If you prefer to use a different environment variable, say PROJECT_HOME, then

var apphome = require('apphome');
var modc = require(apphome('moda/modb/modc', 'PROJECT_HOME'));

test

npm test

Note: For when Proxy is supported, it will be possible to use property access to require a module.

var apphome = require('apphome');
var modc = require(apphome.moda.modb.modc);  //ERROR maybe in the future
npm loves you