{"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"},"repository":{"type":"git","url":"https://github.com/patrick-steele-idem/app-module-path-node"},"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":{},"version":"1.0.2","gitHead":"3df3ae6705a3ae195fd05a638be11f3bd379c813","_id":"app-module-path@1.0.2","_shasum":"ddaf02e39155aa2f831a2306ee5a2d7a2d0d9a1f","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"pnidem","email":"pnidem@gmail.com"},"maintainers":[{"name":"pnidem","email":"pnidem@gmail.com"},{"name":"philidem","email":"phillip.idem@gmail.com"}],"dist":{"shasum":"ddaf02e39155aa2f831a2306ee5a2d7a2d0d9a1f","tarball":"http://registry-npm.ywwl.com/app-module-path/download/app-module-path-1.0.2.tgz","integrity":"sha512-cOhxaS6iD8ZVhRVdTvSKetduw8hfeKYXtGaruH1ifX7ULEaS36qNWiX9DkeZSpClYU0zhm8WMr4EN6RXufhYcw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDilENnBYfI2eXwMVr6X/vC9fXexxN6kuVnqkFz9uqpjAiADcRREDPpiPLfjJJksXxqP8Y4+a509vguOHu6wkjFobw=="}],"size":3914,"noattachment":false,"key":"/app-module-path/-/app-module-path-1.0.2.tgz"},"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":1429755242720,"_cnpm_publish_time":1429755242720,"dist-tags":{"latest":"2.2.0"}}