# processhost

> a ridiculously simple process host

Latest version **1.0.0** (published 2021-01-27) · 0 weekly downloads

## Install

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

## 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.0 |
| Published | 2021-01-27 |
| First published | 2013-07-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 15.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alex Robson |
| Maintainers | a_robson, ifandelse, arobson, brian_edgerton, ianevatt |

## Links

- npm: https://www.npmjs.com/package/processhost
- npm.io page: https://npm.io/package/processhost

## Dependencies (5)

- [mfsm](https://npm.io/package/mfsm.md) ^1.2.0
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [fauxdash](https://npm.io/package/fauxdash.md) ^1.7.0
- [cross-spawn](https://npm.io/package/cross-spawn.md) ^7.0.3
- [topic-dispatch](https://npm.io/package/topic-dispatch.md) ^1.2.0

## Recent versions

- 1.0.0 (latest) — 2021-01-27
- 0.2.3 — 2015-07-31
- 0.2.2 — 2015-05-30
- 0.2.1 — 2015-02-16
- 0.2.0 — 2014-11-12
- 0.1.13 — 2014-05-03
- 0.1.12 — 2014-05-03
- 0.1.11 — 2014-05-02
- 0.1.10 — 2014-05-02
- 0.1.9 — 2014-04-15
- 0.1.8 — 2014-04-14
- 0.1.7 — 2014-04-14
- 0.1.6 — 2014-03-17
- 0.1.4 — 2014-03-14
- 0.1.2 — 2014-03-14
- … 2 more at https://npm.io/package/processhost/versions

## README

# processhost
Simple, cross-platform, process hosting for Node, adapted from [Anvil]'s(https://github.com/anviljs/anvil.js) processhost.

The most useful features are:

 * Reliably kills child processes on host process exit
 * Reliably restarts crashed child processes
 * Apply limits to restart behavior

## API

```javascript
var processes = require( "processhost" )();
```

### configuration
Configuration hash has the following options. Only command and args are required.

```javascript
{
	command: "", // this will probably be "node"
	args: [], // the command line args for the process, i.e. your script
	[cwd]: "", // defaults to current working directory
	[killSignal]: "" | [ "" ], // not required, defaults to "SIGTERM", can provide an array
	[stdio]: "inherit" | "ignore" | "pipe" // determines if the process will write to the console
	[env]: {}, // defaults to the process.env, should be simple hash
	[restart]: true, // control whether or not the process restarts after a start or restart call
	[restartLimit]: 1, // number of allowed restarts
	[restartWindow]: 100 // duration (in ms) of tolerance window
}
```

> Notes

> 1. `restartWindow` defaults to undefined - this results in limitless restarts

> 2. `stdio` defaults to "inherit" causing child processes to share the parents stdout/stderr

### create( processAlias, configuration )
Creates a new process without starting it.
```javascript
processes.create( "myProcess", { command: "node", args: [ "./index.js" ], cwd: "./src" } );
```

### restart( [processAlias] )
If a `processAlias` is provided, only starts|restarts the matching process. Otherwise, this will start|restart ALL processes that have been defined.

```javascript
processes.restart(); // restart all

processes.restart( 'myApp' ); // restart only 'myApp'
```

### setup( processesHash )
Used to define and potentially start multiple processes in a single call.

```javascript
processes.setup( {
	"one": { ... },
	"two": { ... },
	"three": { ... }
} );
```

> Note

> To have the processes started automatically, add a `start`: true to the config block.

### start( processAlias, [configuration] )
If no configuration is provided, this will start|restart the matching process. If a configuration is provided, this will create and start a new process.

```javascript
processes.start( "myProcess", { command: "node", args: [ "./index.js" ], cwd: "./src" } );
```

### stop( [processAlias] )
If no `processAlias` is provided, stops all running processes, otherwise it stops the specified process if it exists and is running.

```javascript
processes.stop();
```

## Events
You can subscribe to the following process level events off the process host.

 * [processAlias].crashed - the process has exited unexpectedly
 * [processAlias].failed - the process has exceeded the set tolerance
 * [processAlias].restarting - the process is restarting
 * [processAlias].started - the process has started
 * [processAlias].stderr
 * [processAlias].stdout
 * [processAlias].stopped - the process has exited after `stop` was called

> Note

> The `stderr` and `stdout` events cannot fire unless you set `stdio` to "pipe" in the config hash.

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