A module installer by the alternative paths where the modules are located.
Install with npm:
$ npm install --save altquire
altrequire was developed as needed to use the AWS Lambda Layer. AWS Lambda Layer fixed the module's location as '/ opt / nodejs / node_modules', and we use a different path when developing. You need altquire as a way to maintain consistency between these two paths.
const alt = require('altquire')(module);
// #1. use as simple as require()
// ---[cwd] cwd/my_module or cwd/node_modules/my_module
// ---[alt] /opt/nodejs/node_modules/my_module
const my_module = alt.require('my_module');
// #2. use when specifying an alternate path alone
// ---[cwd] cwd/my_module or cwd/node_modules/my_module
// ---[alt] /opt/nodejs/my_project/my_module
const my_module = alt.require('my_module', '/opt/nodejs/my_project/');
// #3. use when specifying multiple alternate paths
// ---[cwd] /home/me/aws/lambda/my_project/v2.0/
// ---[alt] /home/me/aws/lambda/my_project/my_module
// ---[alt] /opt/nodejs/my_project/my_module
const my_module = alt.require('my_module', ['my_project/', '/opt/nodejs/my_project/']);
Copyright © 2018, Seunghwan Noh. Released under the MIT License.