{"name":"require-at","version":"1.0.2","main":"require-at.js","description":"Call require pretending your are at another directory","scripts":{"test":"mocha test/spec","coverage":"istanbul cover -- _mocha test/spec && istanbul check-coverage"},"keywords":[],"author":{"name":"Joel Chen"},"license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/jchip/require-at.git"},"dependencies":{},"devDependencies":{"chai":"^3.5.0","istanbul":"^0.4.5","mocha":"^3.2.0"},"engines":{"node":">=4"},"gitHead":"9fada63772e9e59d54f75743b2f6dd6faa1766eb","bugs":{"url":"https://github.com/jchip/require-at/issues"},"homepage":"https://github.com/jchip/require-at#readme","_id":"require-at@1.0.2","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"jchip","email":"joel123@gmail.com"},"dist":{"integrity":"sha512-jux4VpiRDDp3sQX//zyyYScM8stqZUfl/X+Kb6VEtqhIx/qzICEUY6UGrHjNGUX79QSioCULt1DvcOz0ZsBjeg==","shasum":"9f0336723e905bbfcf892ad19eac073e439fcaba","tarball":"http://registry-npm.ywwl.com/require-at/download/require-at-1.0.2.tgz","fileCount":3,"unpackedSize":4867,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb7uusCRA9TVsSAnZWagAATPsP/iiJ+Ll1mfmf7nsIp1xq\nlQWFkYHDQUyGW4qIkbrty6igoyJ64/TJagQMnVwD//WA5xYXSP4tkfsLeHQ3\nuE1aMD+ShWp15Rd9PUk/OrQzlFBpEs/XxiJFxfB3Ayksko2bC2XfDLpDzacG\ndGcuODnTP95CCzcCb7wAc9BRysAkp27PHKhUufe9yPPTUtJR3gDiS0MUWipE\npLVBqYAzKNLgA0UELMCiwUwPwzpnaq8lNgOcSNz0A1FC9tF3N+JwOR17JGbI\nBohZmWBu9FIP+zXiwJCrpk/NdGB5gad0UNgEjWAhpUhnV5qn0Iyb8tYaGSGV\nT7o4fl6dt5BV9WRhxJzmot47Vmt2bxMfJDhz4089hy/rHlXd8oN+jvT/GDpJ\n5HNcOIwzEH9vYHhEiAm/reBvFtkxDQZgs2S6jFuUP+pMTT97tVJpYKSHaAXp\nwl8qsFFE2zRbpnOh05h4d1vvrBTxBKEFBdZrLCfNIH6t9QvS8JWm8FB1+vZ9\nQA8ZdYUd+pF2a0FXKSaZkthXkWj/vAxbD4GG3eCURJXu9Z1ISQPRimVlSbFg\n0le/NUNKMcJp3pzy129WKESAdrZVNrodO0rYrVpEEKyGum8vBrC4GYHk8leQ\nnFpdZ2a+aXWpD4abGOfcSGvc0nTA4Lxr17KjSNfvsJK6KWbKqSJSTcMvwCv7\nHttn\r\n=YCpo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCKgRTR60HgeyAFdkXTnpZnNUIV9N3EU/ST0uFh6XDm/AIgZ22xuE9WMdn3+AL2uszAwCaK91jDs6qsL18gVkLRJW8="}],"size":2070,"noattachment":false,"key":"/require-at/-/require-at-1.0.2.tgz"},"maintainers":[{"name":"jchip","email":"joel123@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/require-at_1.0.2_1542384556153_0.6641421456620866"},"_hasShrinkwrap":false,"readme":"[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]\n[![Dependency Status][daviddm-image]][daviddm-url] [![devDependency Status][daviddm-dev-image]][daviddm-dev-url]\n\n# require-at\n\nAllow you to call `require` or `require.resolve` pretending that you are at another directory.\n\n## Purpose\n\nGiven the directory structure below with two NodeJS apps:\n\n    app1\n    |-+ foo\n    | +-- index.js\n    | +--+ node_modules\n    |    +--+ x \n    |       + ...\n    app2\n    |-+ bar\n    | +-- index.js\n    | +--+ node_modules\n    |    +--+ y\n    |       + ...\n\nWhen you call `require(\"x\")` in `/app1/foo/index.js`, NodeJS will search and find module `x` there.\n\nNow from the same file, if you want to resolve the module `y` under the directory `/app2/bar`, you have to use an absolute or relative path directly pointing to `y`, and you may have to do some searching, probably re-implementing Node's module searching algorithm if you don't know exactly where `y` could be.\n\nHowever, in the file `/app2/bar/index.js`, it can just do `require(\"y\")` and Node would automatically find the module for it, because that file is at the location where `y` is under.\n\nWhat if from the file `/app1/foo/index.js`, you can call `require` as if you were at the directory `/app2/bar`, then you would be able to utilize Node's module searching automatically. \n\nTo achieve this, most other implementations choose to re-implement Node's module searching algorithm.\n\nThis module's approach is to tap into Node's `module` and let it do the work.\n\n## Install\n\n    $ npm install require-at --save\n\n## Usage\n\nA single function is exported.\n\n##### `requireAt(dir, [request])`\n\n-   If you call it with just `dir`, then it returns a `require` function that's been binded to the directory `dir`.  You can use it to load any module as if you are at `dir`.  \n    -   You can also call `require.resolve` with the same effect.\n-   If you call it with `dir` and a `request`, then it will load and return the module `request` as if at `dir`.\n\n##### Example\n\n```js\nconst requireAt = require(\"require-at\");\n\n// get back a require binded to /another/dir\n\nconst requireAtAnother = requireAt(\"/another/dir/\");\nconst modXPath = requireAtAnother.resolve(\"modX\");\nconst modX = requireAtAnother(\"modX\");\n\n// load modY at /another/yet/dir directly\n\nconst modY = requireAt(\"/another/yet/dir\", \"modY\");\n```\n\n## License\n\nApache-2.0 © [Joel Chen](https://github.com/jchip)\n\n[travis-image]: https://travis-ci.org/jchip/require-at.svg?branch=master\n\n[travis-url]: https://travis-ci.org/jchip/require-at\n\n[npm-image]: https://badge.fury.io/js/require-at.svg\n\n[npm-url]: https://npmjs.org/package/require-at\n\n[daviddm-image]: https://david-dm.org/jchip/require-at/status.svg\n\n[daviddm-url]: https://david-dm.org/jchip/require-at\n\n[daviddm-dev-image]: https://david-dm.org/jchip/require-at/dev-status.svg\n\n[daviddm-dev-url]: https://david-dm.org/jchip/require-at?type=dev\n","publish_time":1542384556289,"_cnpm_publish_time":1542384556289,"dist-tags":{"latest":"1.0.6"}}