# spawn-handler

> Simple handler for ChildProcess.spawn, it handles a child process spawned, then executes a callback when the process exits (optional).

Latest version **1.0.1** (published 2014-08-19) · 0 weekly downloads

## Install

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

## 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 | 1.0.1 |
| Published | 2014-08-19 |
| First published | 2014-08-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.10.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Nicolas Tallefourtane |
| Maintainers | nicolab |
| Keywords | spawn, child process, process, command |

## Links

- npm: https://www.npmjs.com/package/spawn-handler
- Repository: https://github.com/Nicolab/node-spawn-handler
- Issues: https://github.com/Nicolab/node-spawn-handler/issues
- npm.io page: https://npm.io/package/spawn-handler

## 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.0.1 (latest) — 2014-08-19
- 1.0.0 — 2014-08-18

## README

# spawn-handler

[![Actual version published on NPM](https://badge.fury.io/js/spawn-handler.png)](https://www.npmjs.org/package/spawn-handler)

Simple handler for ChildProcess.spawn of Node.js, it handles a [child process spawned](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options), then executes a callback when the process exits (optional).

_spawn-handler_ has no external dependencies.


## Quick start

### Install

```sh
npm install spawn-handler
```

### Usage

```js
var spawn = require('spawn-handler');
```

#### spawn.run(command, [args], [options])

Shortcut of 

```js
var spawn = require('child_process').spawn;

spawn(command, [args], [options]);
```

Launches a new process (spawn) with the given `command`.

See the [Node.js doc (spawn)](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) for more details.

```js
var ls = spawn.run('ls', ['-lh', '/usr']);

ls.stdout.on('data', function (data) {
  console.log('stdout: ' + data);
});

ls.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});

ls.on('close', function (code) {
  console.log('child process exited with code ' + code);
});
```


#### spawn.handle(child, [done], [name])

Spawn handler.

```js
var ls = spawn.handle(spawn.run('ls', ['./']), function(code) {
  console.log('Command exited with code ' + code);
}, 'List current directory');

ls.stdout.on('data', function(data) {
  console.log('files: ' + data);
});

ls.stderr.on('data', function (data) {
  console.log('stderr: ' + data);
});
```


## Testing

_spawn-handler_ [is tested](test/src/index.js) with [Unit.js](http://unitjs.com) and Mocha.
Unit.js is a powerful and intuitive unit testing framework for javascript.


## License

[MIT](https://github.com/Nicolab/node-spawn-handler/blob/master/LICENSE) (c) 2013, Nicolas Tallefourtane.


## Author

| [![Nicolas Tallefourtane - Nicolab.net](http://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](http://nicolab.net) |
|---|
| [Nicolas Talle](http://nicolab.net) |
| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) |

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