src/index.js
function getInstalledPathSync (name, opts) {
  if (!isValidString(name)) {
    throw new TypeError('get-installed-path: expect `name` to be string')
  }

  const filePaths = defaults(name, opts)
  const firstPath = filePaths[0]
  const modulePath = filePaths.find((filePath) => {
    let stat = null

    try {
      stat = fs.statSync(filePath)
    } catch (e) {
      return false
    }

    if (stat.isDirectory()) {
      return true
    }

    const msg = `Possibly "${name}" is not a directory: ${filePath}`
    throw new Error('get-installed-path: some error occured! ' + msg)
  })

  if (!modulePath) {
    const label = 'get-installed-path:'
    const msg = `${label} module not found "${name}" in path ${firstPath}`
    throw new Error(msg)
  }

  return modulePath
}
function getInstalledPathSync (name, opts) {
  if (!isValidString(name)) {
    throw new TypeError('get-installed-path: expect `name` to be string')
  }

  const filePaths = defaults(name, opts)
  const firstPath = filePaths[0]
  const modulePath = filePaths.find((filePath) => {
    let stat = null

    try {
      stat = fs.statSync(filePath)
    } catch (e) {
      return false
    }

    if (stat.isDirectory()) {
      return true
    }

    const msg = `Possibly "${name}" is not a directory: ${filePath}`
    throw new Error('get-installed-path: some error occured! ' + msg)
  })

  if (!modulePath) {
    const label = 'get-installed-path:'
    const msg = `${label} module not found "${name}" in path ${firstPath}`
    throw new Error(msg)
  }

  return modulePath
}
function getInstalledPathSync ( name , opts ) { if ( ! isValidString ( name ) ) { throw new TypeError ( 'get-installed-path: expect `name` to be string' ) } const filePaths = defaults ( name , opts ) const firstPath = filePaths [ 0 ] const modulePath = filePaths . find ( ( filePath ) => { let stat = null try { stat = fs . statSync ( filePath ) } catch ( e ) { return false } if ( stat . isDirectory ( ) ) { return true } const msg = ` ${ name } ${ filePath } ` throw new Error ( 'get-installed-path: some error occured! ' + msg ) } ) if ( ! modulePath ) { const label = 'get-installed-path:' const msg = ` ${ label } ${ name } ${ firstPath } ` throw new Error ( msg ) } return modulePath }
> Get installed path of a `name` package synchronous.
Returns `boolean` when `paths` option is used and filepath is directory,
otherwise returns a full filepath OR throws error.

@example
const { getInstalledPathSync } = require('get-installed-path')

const npmPath = getInstalledPathSync('npm')
console.log(npmPath)
// => '/home/charlike/.nvm/path/to/lib/node_modules/npm'

const gmPath = getInstalledPathSync('global-modules', { local: true })
console.log(gmPath)
// => '~/code/get-installed-path/node_modules/global-modules'

@param  {string} name package name
@param  {Object} opts pass `opts.local` to check locally
@return {string} The full filepath or throw `TypeError` if `name` not a string or is empty string
@name   getInstalledPathSync
@public
> Get installed path of a name package synchronous . Returns boolean when paths option is used and filepath is directory otherwise returns a full filepath OR throws error .