# npmi

> Gives a simplier API to npm install (programatically installs stuffs)

Latest version **4.0.0** (published 2017-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install npmi
pnpm add npmi
yarn add npmi
bun add npmi
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2017-11-20 |
| First published | 2014-01-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 82 |
| Author | Maxime Tricoire |
| Maintainers | leiko |
| Keywords | npm, install, api, programatically |

## Links

- npm: https://www.npmjs.com/package/npmi
- Repository: https://github.com/maxleiko/npmi
- Issues: https://github.com/maxleiko/npmi/issues
- npm.io page: https://npm.io/package/npmi

## Dependencies (2)

- [semver](https://npm.io/package/semver.md) ^5.4.1
- [global-npm](https://npm.io/package/global-npm.md) ^0.3.0

## Recent versions

- 4.0.0 (latest) — 2017-11-20
- 2.0.1-alpha (next) — 2015-12-03
- 3.0.0 — 2017-07-27
- 2.0.1 — 2016-04-21
- 1.0.1 — 2015-03-23
- 1.0.0 — 2015-01-26
- 0.1.2 — 2014-12-16
- 0.1.1 — 2014-10-28
- 0.1.0 — 2014-10-28
- 0.0.12 — 2014-08-01
- 0.0.10 — 2014-06-18
- 0.0.9 — 2014-06-04
- 0.0.8 — 2014-05-05
- 0.0.7 — 2014-04-07
- 0.0.6 — 2014-03-26
- … 5 more at https://npm.io/package/npmi/versions

## README

npmi [![Build Status](https://travis-ci.org/maxleiko/npmi.svg)](https://travis-ci.org/maxleiko/npmi)
====
NodeJS package that gives a simplier API to npm install (programatically installs things)

[![NPM](https://nodei.co/npm/npmi.png?downloads=true&downloadRank=true)](https://nodei.co/npm/npmi/)

### npmi versions scheme
 - **^1**: uses `npm@^2`
 - **^2**: uses `npm@^3`
 - **^3**: uses `npm@^5`
 - **^4**: uses [`global-npm`](https://github.com/dracupid/global-npm) (meaning `npm` is no longer a dependency of `npmi`)

> :warning: Be advised that `npm` in its `v5+` will symlink local modules from the destination directory to the actual module directory instead of "installing" them old-school style (which is a breaking change regarding the previous npm versions)

### Options
#### options.name
__Type:__ `String`
__Optional:__ `true`

If you don't specify a `name` in options, but just a `path`, __npmi__ will do the same as if you were at this path in a terminal and executing `npm install`  
Otherwise, it will install the module specified by this name like `npm install module-name` does.

#### options.version
__Type:__ `String`
__Optional:__ `true`
__Default__ `'latest'`

Desired version for installation

#### options.path
__Type:__ `String`
__Optional:__ `true`
__Default__ `'.'`

Desired location for installation (note that if you specified /some/foo/path, __npm__ will automatically create a `node_modules` sub-folder at this location, resulting in `/some/foo/path/node_modules`). So don't specify the `node_modules` part in your path

#### options.forceInstall
__Type:__ `Boolean`
__Optional:__ `true`
__Default__ `false`

If true, __npmi__ will install `options.name` module even though it has already been installed.  
If false, __npmi__ will check if the module is already installed, if it is, it will also check if the installed version is equal to `options.version`, otherwise, it will install `options.name@options.version`

#### options.localInstall
__Type:__ `Boolean`
__Optional:__ `true`
__Default__ `false`

Allows __npmi__ to install local module that are not on __npm registry__. If, you want to install a local module by specifying its full path in `options.name`, you need to set this to `true`.

#### options.npmLoad
__Type:__ `Object`
__Optional:__ `true`
__Default__ `{loglevel: 'silent'}`

This object is given to __npm__ and allows you to do some fine-grained npm configurations.  
It is processed by __npm__ like command-line arguments but within an Object map ([npm-config](https://www.npmjs.org/doc/misc/npm-config.html))

### Usage example
```js
var npmi = require('npmi');
var path = require('path');

console.log(npmi.NPM_VERSION); // prints the installed npm version used by npmi


var options = {
	name: 'your-module',	// your module name
	version: '0.0.1',		// expected version [default: 'latest']
	path: '.',				// installation path [default: '.']
	forceInstall: false,	// force install if set to true (even if already installed, it will do a reinstall) [default: false]
	npmLoad: {				// npm.load(options, callback): this is the "options" given to npm.load()
		loglevel: 'silent'	// [default: {loglevel: 'silent'}]
	}
};
npmi(options, function (err, result) {
	if (err) {
		if 		(err.code === npmi.LOAD_ERR) 	console.log('npm load error');
		else if (err.code === npmi.INSTALL_ERR) console.log('npm install error');
		return console.log(err.message);
	}

	// installed
	console.log(options.name+'@'+options.version+' installed successfully in '+path.resolve(options.path));
});
```

### Acknowledgements
This work has been done in the context of the [HEADS Project](http://heads-project.eu/)  
![HEADS LOGO](heads-logo.png)

### Contributors
 - [lukaskollmer](https://github.com/lukaskollmer)
 - [karanjthakkar](https://github.com/karanjthakkar)

---
_Source: https://npm.io/package/npmi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
