Get installation path where the given package is installed. Works for globally and locally installed packages
npm install get-installed-path> Get installation path where the given package is installed. Works for globally and locally installed packages
You might also be interested in detect-installed.
[![Code Climate][codeclimate-img]][codeclimate-url]
[![Code Style Standard][standard-img]][standard-url]
[![Linux Build][travis-img]][travis-url]
[![Code Coverage][codecov-img]][codecov-url]
[![Dependencies Status][dependencies-img]][dependencies-url]
[![Renovate App Status][renovate-img]][renovate-url]
[![Node Version Required][nodeversion-img]][nodeversion-url]
If you have any _how-to_ kind of questions, please read Code of Conduct and join the chat room or [open an issue][open-issue-url].
You may also read the Contributing Guide. There, beside _"How to contribute?"_, we describe everything _stated_ by the badges.
[![tunnckoCore support][chat-img]][chat-url]
[![Code Format Prettier][prettier-img]][prettier-url]
[![Node Security Status][nodesecurity-img]][nodesecurity-url]
[![Conventional Commits][ccommits-img]][ccommits-url]
[![Semantic Release][semantic-release-img]][semantic-release-url]
[![First Timers Only][first-timers-only-img]][first-timers-only-url]
[![All Contributors Spec][all-contributors-img]](#contributors)
[![Make A Pull Request][prs-welcome-img]][prs-welcome-url]
[![Newsletter Subscribe][tinyletter-img]][tinyletter-url]
[![PayPal Author Support][paypal-donate-img]][paypal-donate-url]
[![Share Love][share-love-img]][share-love-url]
[![BitHound Code][bithound-code-img]][bithound-code-url]
_(TOC generated by verb using markdown-toc)_
This project requires [Node.js][nodeversion-url] v6 and above. Use yarn v1 / npm v5 or above to install it.
```
$ yarn add get-installed-path
> Get installed path of globally or locally name package.name
By default it checks if exists as directory in [global-modules][]opts.local
directory of the system. Pass to get path of nameopts.cwd
package from local directory or from . Returns rejectednode_modules
promise if module not found in global/local folder or
if it exist but is not a directory.
Params
* name {string}: package name opts
* {Object}: pass opts.local to check locally returns
* {Promise}: rejected promise if name not a string or is empty string
Example
`jsx
const { getInstalledPath } = require('get-installed-path')
getInstalledPath('npm').then((path) => {
console.log(path)
// => '/home/charlike/.nvm/path/to/lib/node_modules/npm'
})
getInstalledPath('foo-bar-barwerwlekrjw').catch((err) => {
console.log(err.message)
// => 'module not found "foo-bar-barwerwlekrjw" in path ...'
})
getInstalledPath('npm', {
local: true
}).catch((err) => {
console.log(err.message)
// => 'module not found "foo-bar-barwerwlekrjw" in path ...'
})
getInstalledPath('global-modules', {
local: true
}).then((path) => {
console.log(path)
// => '~/code/get-installed-path/node_modules/global-modules'
})
// If you are using it for some sub-directory
// pass opts.cwd to be where the node_modules
// folder is.
process.chidr('foo-bar-baz')
getInstalledPath('global-modules', {
local: true,
cwd: '../'
}).then((path) => {
console.log(path)
// => '~/code/get-installed-path/node_modules/global-modules'
})
// When searching for the path of a package that is required
// by several other packages, its path may not be in the
// closest node_modules. In this case, to search recursively,
// you can use the following:
getInstalledPath('npm', {
paths: process.mainModule.paths
}).then((path) => {
// ...
})
// process.mainModule refers to the location of the current`
// entry script.
> Get installed path of a name package synchronous.boolean
Returns when paths option is used and filepath is directory,
otherwise returns a full filepath OR throws error.
Params
* name {string}: package name opts
* {Object}: pass opts.local to check locally returns
* {string}: The full filepath or throw TypeError if name not a string or is empty string
Example
`jsx
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'
``
*
_This file was generated by verb-generate-readme, v0.6.0, on October 12, 2017._
Project scaffolded and managed with [hela][].
[always-done]: https://github.com/hybridables/always-done
[async-done]: https://github.com/gulpjs/async-done
[base]: https://github.com/node-base/base
[charlike-cli]: https://github.com/tunnckoCore/charlike-cli
[dezalgo]: https://github.com/npm/dezalgo
[global-modules]: https://github.com/jonschlinkert/global-modules
[hela]: https://github.com/tunnckoCore/hela
[once]: https://github.com/isaacs/once
[npmv-url]: https://www.npmjs.com/package/get-installed-path
[npmv-img]: https://img.shields.io/npm/v/get-installed-path.svg?label=npm%20version
[open-issue-url]: https://github.com/tunnckoCore/get-installed-path/issues/new
[github-release-url]: https://github.com/tunnckoCore/get-installed-path/releases/latest
[github-release-img]: https://img.shields.io/github/release/tunnckoCore/get-installed-path.svg?label=github%20release
[license-url]: https://github.com/tunnckoCore/get-installed-path/blob/master/LICENSE
[license-img]: https://img.shields.io/npm/l/get-installed-path.svg
[downloads-weekly-img]: https://img.shields.io/npm/dw/get-installed-path.svg
[downloads-monthly-img]: https://img.shields.io/npm/dm/get-installed-path.svg
[downloads-total-img]: https://img.shields.io/npm/dt/get-installed-path.svg
[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/get-installed-path
[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/get-installed-path.svg
[standard-url]: https://github.com/standard/standard
[standard-img]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[travis-url]: https://travis-ci.org/tunnckoCore/get-installed-path
[travis-img]: https://img.shields.io/travis/tunnckoCore/get-installed-path/master.svg?label=linux
[codecov-url]: https://codecov.io/gh/tunnckoCore/get-installed-path
[codecov-img]: https://img.shields.io/codecov/c/github/tunnckoCore/get-installed-path/master.svg
[dependencies-url]: https://david-dm.org/tunnckoCore/get-installed-path
[dependencies-img]: https://img.shields.io/david/tunnckoCore/get-installed-path.svg
[renovate-url]: https://renovateapp.com
[renovate-img]: https://img.shields.io/badge/renovate-enabled-brightgreen.svg
[chat-url]: https://tunnckocore.flock.com/?i=cx2xoeofjtj6eo6c
[chat-img]: https://img.shields.io/badge/chat-on_flock-brightgreen.svg
[prettier-url]: https://github.com/prettier/prettier
[prettier-img]: https://img.shields.io/badge/styled_with-prettier-f952a5.svg
[nodesecurity-url]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/fd91a3c7-498b-4ff8-8f29-5d93a9d97626
[nodesecurity-img]: https://nodesecurity.io/orgs/tunnckocore-dev/projects/fd91a3c7-498b-4ff8-8f29-5d93a9d97626/badge
[semantic-release-url]: https://github.com/semantic-release/semantic-release
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[ccommits-url]: https://conventionalcommits.org/
[ccommits-img]: https://img.shields.io/badge/conventional_commits-1.0.0-yellow.svg
[nodeversion-url]: https://nodejs.org/en/download
[nodeversion-img]: https://img.shields.io/node/v/get-installed-path.svg
[first-timers-only-img]: https://img.shields.io/badge/first--timers--only-friendly-blue.svg
[first-timers-only-url]: http://www.firsttimersonly.com
[prs-welcome-img]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
[prs-welcome-url]: http://makeapullrequest.com
[all-contributors-img]: https://img.shields.io/github/contributors/tunnckoCore/get-installed-path.svg?label=all%20contributors&colorB=ffa500
[bithound-deps-url]: https://www.bithound.io/github/tunnckoCore/get-installed-path/master/dependencies/npm
[bithound-deps-img]: https://www.bithound.io/github/tunnckoCore/get-installed-path/badges/dependencies.svg
[bithound-code-url]: https://www.bithound.io/github/tunnckoCore/get-installed-path/master
[bithound-code-img]: https://www.bithound.io/github/tunnckoCore/get-installed-path/badges/code.svg
[paypal-donate-url]: https://paypal.me/tunnckoCore/10
[paypal-donate-img]: https://img.shields.io/badge/paypal-donate-009cde.svg
[tinyletter-url]: https://tinyletter.com/tunnckoCore
[tinyletter-img]: https://img.shields.io/badge/newsletter-subscribe-9caaf8.svg
[share-love-url]: https://twitter.com/intent/tweet?text=https://github.com/tunnckoCore/get-installed-path&via=tunnckoCore
[share-love-img]: https://img.shields.io/badge/share-♥-ed1c24.svg