{"name":"app-module-path","description":"Simple module to add additional directories to the Node module search for top-level app modules","main":"lib/index.js","scripts":{"test":"node test/test.js && ./node_modules/mocha/bin/mocha test/test2.js"},"repository":{"type":"git","url":"git+https://github.com/patrick-steele-idem/app-module-path-node.git"},"keywords":["modules","path","node","extend","resolve"],"author":{"name":"Patrick Steele-Idem","email":"pnidem@gmail.com"},"license":"BSD-2-Clause","bugs":{"url":"https://github.com/patrick-steele-idem/app-module-path-node/issues"},"homepage":"https://github.com/patrick-steele-idem/app-module-path-node","publishConfig":{"registry":"https://registry.npmjs.org/"},"ebay":{},"devDependencies":{"chai":"^3.5.0","mocha":"^3.2.0"},"version":"2.2.0","gitHead":"e0942e24b37ab7e7259ea4c822d157d8d8aa3787","_id":"app-module-path@2.2.0","_shasum":"641aa55dfb7d6a6f0a8141c4b9c0aa50b6c24dd5","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.5.0","_npmUser":{"name":"pnidem","email":"pnidem@gmail.com"},"dist":{"shasum":"641aa55dfb7d6a6f0a8141c4b9c0aa50b6c24dd5","tarball":"http://registry-npm.ywwl.com/app-module-path/download/app-module-path-2.2.0.tgz","npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2jnECRA9TVsSAnZWagAAit4P/ipoQBeFimEJel4Hqu9m\nkdmydjgdCUHhVJ38PwA4ufp2cn/ChBUzTsRWPPUPwaYScING3xP8JOn9Ncv9\nV5RGO8pcOvox0H0nRmpeSi9G2hEndSY3+f679J/cZRlo8ATCo22X5Q9Je/HS\nWB3mIWF9K6Mn+3R5v9IbvdepVL2N5+tDqmbeM81WPVqgkPVa06JLnHrGtT4b\naBvs3fu/mwRHQO6R2cNN9wyAR3kcDxIvnDEYMl/CFHA1zalYwIifHdCxOG5B\n2dFT5WfRopasOLOUaoQon6YZAf8lcb8LCFM/5XsGeZN+rm9pKK0tz2Oeg7pE\nu5ppS/QA09pBhDaSegLzo7cKopCrMixlAa5oTAjD3h/o8avsZcgxv0ZuS3GM\n8/ZnIwhLA5sNjlJ/TWYzKX//i6W2Jz5tVbz3EyjZpFuYH8x24IVHmUP3+bV6\nLYLsdc7i/0T6ZINUE0gQvEdNxoY/BVioXzpAWQNJeWCgwBv2USnGdEpNpD2n\nDsCi4GtLWnfO8N0BAc6cN9yD/ldrEX8wCSHOUb4ERwC5OmvexxljvVBCZ3qJ\nEb1BSfPmRCJ13FYAQHWY82W1Xe0bCYR7OQSyzd6C+IfZXEpnmYrqBFEGBIC6\nZcugfJUUrmbowIDBMawsJlBlBF+kidi5DOZC+5QN55EKPMFA8FqFSuAA1pSw\ntiuO\r\n=1bf3\r\n-----END PGP SIGNATURE-----\r\n","integrity":"sha512-gkco+qxENJV+8vFcDiiFhuoSvRXb2a/QPqpSoWhVz829VNJfOTnELbBmPmNKFxf3xdNnw4DWCkzkDaavcX/1YQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCtM2nyKCEQQrt5O73rd+NfvrMkC5YsWMG9WvrXfhjWTQIgR6T++qVIB+NAtbBsIktmtfuQogZLKvrt41WeEFRc7IY="}],"size":6670,"noattachment":false,"key":"/app-module-path/-/app-module-path-2.2.0.tgz"},"maintainers":[{"name":"mlrawlings","email":"ml.rawlings@gmail.com"},{"name":"philidem","email":"phillip.idem@gmail.com"},{"name":"pnidem","email":"pnidem@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/app-module-path-2.2.0.tgz_1483646230485_0.8301258084829897"},"directories":{},"readme":"[![NPM](https://nodei.co/npm/app-module-path.png?downloads=true)](https://nodei.co/npm/app-module-path/)\n\napp-module-path\n=====================\n\nThis simple module enables you to add additional directories to the Node.js module search path (for top-level app modules only). This allows application-level modules to be required as if they were installed into the `node_modules` directory.\n\n## Installation\n\n`npm install app-module-path --save`\n\n## Usage\n```javascript\n// ***IMPORTANT**: The following line should be added to the very\n//                 beginning of your main script!\nrequire('app-module-path').addPath(baseDir);\n```\n\n__IMPORTANT:__\nThe search path should be modified before any modules are loaded!\n\n__Example:__\n\nIn your `my-app/index.js` (or `my-app/server.js`) file:\n```javascript\n// Add the root project directory to the app module search path:\nrequire('app-module-path').addPath(__dirname);\n```\n\nGiven the following example directory structure:\n\n- **my-app/**\n    - **src/** - Source code and application modules directory\n        - **foo/** - A module directory\n            - index.js\n        - **bar/** - Another module directory\n            - index.js\n    - **node_modules/** - Installed modules\n        - **installed-baz/** - An installed module\n            - index.js\n    - index.js - Main script\n\nThe following will work for any modules under the `src` directory:\n```javascript\n// All of the following lines will work in \"src/foo/index.js\" and \"src/bar/index.js\":\nvar foo = require('src/foo'); // Works\nvar bar = require('src/bar'); // Works\nvar baz = require('installed-baz'); // Works\n```\n\nLastly, by design, installed modules (i.e. modules under the `node_modules` directory) will not be able to require application-level modules so the following will ___not___ work:\n\n```javascript\n// All of the following lines will *not* work in \"node_modules/installed-baz/index.js\"!\nvar foo = require('src/foo'); // Fails\nvar bar = require('src/bar'); // Fails\n```\n\n## Alternate Usage (`app-module-path/register`)\n\nThis module supports an alternate method of adding a path to the Node.js module search path that requires less code. Requiring or importing the `app-module-path/register` module will result in the directory of the calling module being added to the Node.js module search path as shown below:\n\n## Explicitly enabling a directory/package\n\nBy default, `app-module-path` will not attempt to resolve app modules from a directory that is found to be within a `node_modules` directory. This behavior can be changed by explicitly enabling `app-module-path` to work for descendent modules of a specific directory. For example:\n\n```javascript\nvar packageDir = path.dirname(require.resolve('installed-module-allowed'));\nrequire('../').enableForDir(packageDir);\n```\n\n\n### ES5\n\n```javascript\nrequire('app-module-path/register');\n\n// Is equivalent to:\nrequire('app-module-path').addPath(__dirname);\n```\n\n### ES6\n\n```javascript\nimport \"app-module-path/register\";\n\n// Is equivalent to:\nimport { addPath } from 'app-module-path';\naddPath(__dirname);\n```\n\n## Alternative Usage (`app-module-path/cwd`)\n\nAdditionally, requiring or importing `app-module-path/cwd` will result in the current working directory of the Node.js process being added to the module search path as shown below:\n\n### ES5\n\n```javascript\nrequire('app-module-path/cwd');\n\n// Is equivalent to:\nrequire('app-module-path').addPath(process.cwd());\n```\n\n### ES6\n\n```javascript\nimport \"app-module-path/cwd\";\n\n// Is equivalent to:\nimport { addPath } from 'app-module-path';\naddPath(process.cwd());\n```\n\n## Additional Notes\n\n* __Search path order:__\n    * App module paths will be added to the end of the default module search path. That is, if a module with the same name exists in both a `node_modules` directory and an application module directory then the module in the `node_modules` directory will be loaded since it is found first.\n    *This behavior is new in v2.x. In v1.x, this search order was reversed*\n\n* __Node.js compatibility:__\n    * This module depends on overriding/wrapping a built-in Node.js method, and it is possible (but unlikely) that this behavior could be broken in a future release of Node.js (at which point a workaround would need to be used)\n    * This module will _not_ change or break modules installed into the `node_modules` directory.\n* __Recommendations:__\n    * Since this module changes the Node.js convention of how non-relative modules are resolved, it is recommended (but not required) to put all app modules in a common directory below the application root (such as `my-app/src` or `my-app/app_modules`) and then to add the application root to the search path. The require calls would then be something like `require('src/foo')` or `require('app_modules/foo')`. The common prefix makes it more clear that the module can be found in the application's modules directory and not in the `node_modules` directory.\n\n\n## Contribute\nPull requests, bug reports and feature requests welcome.\n\n## License\n\nBSD-2-Clause\n","publish_time":1483646232201,"_cnpm_publish_time":1483646232201,"dist-tags":{"latest":"2.2.0"}}