resolve-npm-which

finds the user's path for a module like browserify

Usage no npm install needed!

<script type="module">
  import resolveNpmWhich from 'https://cdn.skypack.dev/resolve-npm-which';
</script>

README

resolve-npm-which

stable

For a CLI module like "browserify" or "watchify", resolves to the path for that module in local or global installs.

var find = require('resolve-npm-which')

find('browserify', {
  basedir: process.cwd()
}, function(err, file) {
  if (err) throw err
  
  // now require it !
  var browserify = require(file)
})

First it will use the resolve algorithm to look through locals, and then it will fall back to npm-which to look through globals.

The callback provides the path to the module so that it can be required.

Usage

NPM

find(name, opt, cb)

Finds the module name with the given options (passed to resolve), then calls cb with the error/success state.

Options must include basedir to search for.

Test

Note: To test, you need to have browserify installed gobally, and npm config get prefix should return a meaningful value.

License

MIT, see LICENSE.md for details.