https://github.com/sdgluck/require-local-node-module
Require a module from cwd's node_modules folder
https://github.com/sdgluck/require-local-node-module
Last synced: 8 months ago
JSON representation
Require a module from cwd's node_modules folder
- Host: GitHub
- URL: https://github.com/sdgluck/require-local-node-module
- Owner: sdgluck
- License: mit
- Created: 2017-08-10T22:12:27.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-02T14:26:24.000Z (almost 9 years ago)
- Last Synced: 2025-10-08T20:22:56.672Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# require-local-node-module
> Require a module from cwd's node_modules folder (for CLIs)
Require a Node module from the current working directory's nearest `node_modules` folder.
This is useful for a CLI application that, for example, has a peer dependency on a
module that should be the same version as is being used by whatever program lives
in the CWD.
See also: [`require-global-node-module`](https://github.com/sdgluck/require-global-node-module)
## Install
```sh
npm install --save require-local-node-module
```
```sh
yarn add require-local-node-module
```
## Import
```js
// ES2015
import requireLocal from 'require-local-node-module'
```
```sh
// CommonJS
var requireLocal = require('require-local-node-module')
```
## Usage
### `requireLocal (module[, opts]) : *`
Require a module from the nearest `node_modules` folder.
- __module__ {String} (required) Name of the module to require
- __opts__ {Object} (optional) Options object
Returns the required module as per usual calls to `require`.
#### Options:
- distance {Number} Number of folders to climb in search for the module (default: `3`)
- folder {String} Name of the folder where the module lives (default: `'node_modules'`)
## Contributing
All pull requests and issues welcome!
If you're not sure how, check out the [great video tutorials on egghead.io](http://bit.ly/2aVzthz)!
## License
MIT © [Sam Gluck](github.com/sdgluck)