# spawn-npm-install

> programmatically install npm dependencies

Latest version **1.3.0** (published 2024-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install spawn-npm-install
pnpm add spawn-npm-install
yarn add spawn-npm-install
bun add spawn-npm-install
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2024-08-23 |
| First published | 2015-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | npm, install, installation, installs, cli, api, run, save, dev, save-dev, --save-dev, uninstall, spawn, --save, dependencies, deps |

## Links

- npm: https://www.npmjs.com/package/spawn-npm-install
- Repository: https://github.com/mattdesl/spawn-npm-install
- Issues: https://github.com/mattdesl/spawn-npm-install/issues
- npm.io page: https://npm.io/package/spawn-npm-install

## Dependencies (1)

- [dargs](https://npm.io/package/dargs.md) ^4.0.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.3.0 (latest) — 2024-08-23
- 1.2.0 — 2015-07-12
- 1.1.0 — 2015-05-05
- 1.0.4 — 2015-04-30
- 1.0.3 — 2015-04-30
- 1.0.2 — 2015-04-30
- 1.0.1 — 2015-04-30
- 1.0.0 — 2015-04-30

## README

# spawn-npm-install

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Programmatically install/uninstall npm dependencies by spawning a `npm` child process.

```js
var install = require('spawn-npm-install')

install(['through2', 'quote-stream'], { saveDev: true }, function(err) {
  if (err)
    console.error("Could not install:\n" + err.message)
  else
    console.log("Installed.")
})
```

Returns the child process, so you can print install log/warnings like so:

```js
var proc = install('tape')
proc.stderr.pipe(process.stderr)
proc.stdout.pipe(process.stdout)
```

Or, to preserve log output and colors:

```js
install('tape', { stdio: 'inherit' })
```

PRs welcome.

## Usage

[![NPM](https://nodei.co/npm/spawn-npm-install.png)](https://www.npmjs.com/package/spawn-npm-install)

#### `spawn = require('spawn-npm-install')`
#### `proc = spawn.install(dependencies, [opt], [cb])`

Spawns an `npm install` using the given `dependencies` (string or array of strings). You can pass `opt` to the command, which will convert [camel case to dash-case](https://www.npmjs.com/package/dargs) for the CLI arguments. The last parameter `cb` is the callback which is passed `(err)` on failure, or null otherwise.

You can specify a `command` for options to use instead of the default `npm` (e.g. for specialized [analytics](https://github.com/mattdesl/npm-install-analytics) or other hooks).

Also accepts some options for the [child process](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options):

- `env` environment variables
- `stdio` the standard err/out
- `cwd` the current working directory

Returns the child process.

Examples:

```js
var install = require('spawn-npm-install')
install('tape', { saveDev: true }, done)

install(['zalgo', 'img'], function(err) {
  if (err) 
    console.error(err.message)
})
```

The default export `spawn` is the same as `spawn.install`, for symmetry.

#### `proc = spawn.uninstall(dependencies, [opt], [cb])`

The same as above, but triggers `npm uninstall` instead. 

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/spawn-npm-install/blob/master/LICENSE.md) for details.

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