find-node-module
by Vytenis Urbonavičius
This library/utility retrieves absolute path to a locally installed node module.
It is sometimes necessary to directly access some file from inside node_modules. Problem is - technically there can be multiple node_modules available starting from project root directory and going up from there. These node_modules are resolved recursively and there is absolutely no guarantee that a specific module will always be available at the same location. All in all - hard-coding path to something inside node_modules is a very bad idea.
find-node-module provides a way to avoid such hard-coding by locating which path would actually be used when requiring. This is achieved by creating a wrapper on top of find-node-modules library.
Installation
Local:
npm install find-node-module
Global:
npm install -g find-node-module
Usage
let NodeModules = require('find-node-module').NodeModules
let nodeModules = new NodeModules(__dirname);
let modulePath = nodeModules.find('npm-dts-webpack-plugin')
CLI Usage
To see usage examples - run without arguments:
find-node-module
Typical usage (using global install):
cd /your/project
find-node-module npm-dts-webpack-plugin