npm-install-global
Version:
Simple API for globally installing or uninstalling one or more NPM packages.
182 lines (116 loc) • 5.28 kB
Markdown
# npm-install-global [](https://www.npmjs.com/package/npm-install-global) [](https://npmjs.org/package/npm-install-global) [](https://npmjs.org/package/npm-install-global) [](https://travis-ci.org/jonschlinkert/npm-install-global)
> Simple API for globally installing or uninstalling one or more NPM packages.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save npm-install-global
```
Install with [yarn](https://yarnpkg.com):
```sh
$ yarn add npm-install-global
```
## Usage
```js
var npm = require('npm-install-global');
// easily install packages
npm.install('generate', function(err) {
if (err) return console.log(err);
});
// or remove outdated packages
npm.uninstall('yeoman', function(err) {
if (err) return console.log(err);
});
// or install only packages that don't already exist
npm.maybeInstall(['foo', 'bar'], function(err) {
if (err) return console.log(err);
});
```
## API
### [npm](index.js#L29)
Execute `npm --global` with the given command and one or more package names. This is the base for [install](#install) and [uninstall](#uninstall).
**Params**
* `names` **{String|Array}**: One or more package names.
* `cb` **{Function}**: Callback
**Example**
```js
npm('install', 'verb', function(err) {
if (err) throw err;
});
```
### [.global](index.js#L65)
Execute `npm [cmd] --global` with one or more package `names`.
**Params**
* `cmd` **{String}**: The command to run
* `names` **{String|Array}**: One or more package names.
* `cb` **{Function}**: Callback
**Example**
```js
npm.global('install', 'generate', function(err) {
if (err) throw err;
});
```
### [.install](index.js#L82)
Execute `npm install --global` with one or more package `names`.
**Params**
* `names` **{String|Array}**: One or more package names.
* `cb` **{Function}**: Callback
**Example**
```js
npm.install('generate', function(err) {
if (err) throw err;
});
```
### [.maybeInstall](index.js#L99)
Install the given packages if they are not already installed.
**Params**
* `names` **{String|Array}**: One or more package names.
* `cb` **{Function}**: Callback
**Example**
```js
npm.maybeInstall(['foo', 'bar', 'baz'], function(err) {
if (err) throw err;
});
```
### [.uninstall](index.js#L131)
Execute `npm uninstall --global` with one or more package `names`.
**Params**
* `names` **{String|Array}**: One or more package names.
* `cb` **{Function}**: Callback
**Example**
```js
npm.uninstall('yeoman', function(err) {
if (err) throw err;
});
```
## History
**v1.0.0**
* adds [.global](#global) method, now used by the other methods
**v0.1.1**
* adds [.maybeInstall](#maybeInstall) method
## About
### Related projects
* [base-npm](https://www.npmjs.com/package/base-npm): Base plugin that adds methods for programmatically running npm commands. | [homepage](https://github.com/node-base/base-npm "Base plugin that adds methods for programmatically running npm commands.")
* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality node.js applications, using plugins like building blocks")
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Building docs
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
### Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install && npm test
```
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 29, 2017._