# @ideadesignmedia/subprocess

> Easily create and manage subprocesses through json signals.

Latest version **1.1.1** (published 2024-03-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ideadesignmedia/subprocess
pnpm add @ideadesignmedia/subprocess
yarn add @ideadesignmedia/subprocess
bun add @ideadesignmedia/subprocess
```

## 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.1.1 |
| Published | 2024-03-22 |
| First published | 2023-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ideadesignmedia |

## Links

- npm: https://www.npmjs.com/package/@ideadesignmedia/subprocess
- npm.io page: https://npm.io/package/@ideadesignmedia/subprocess

## Dependencies (1)

- [node-abort-controller](https://npm.io/package/node-abort-controller.md) ^3.1.1

## Recent versions

- 1.1.1 (latest) — 2024-03-22
- 1.1.0 — 2023-08-22
- 1.0.1 — 2023-04-12
- 1.0.0 — 2023-04-12

## README

# Subprocess Helper

Easily create and manage subprocesses through json signals.

## Usage

```const { createSubprocess, handleMain } = require('@ideadesignmedia/subprocess')```

### createSubprocess
```createSubprocess(command, args = [], options = {}, onSignal: ({type: string, data: any}) => void) => { child, eventManager request, send, close, id }```

Creates a subprocess and returns a function to send signals to it.

##### Inputs

```command``` - The command to run in the subprocess.

```args``` - The arguments to pass to the command.

```options``` - The options to pass to the child process. If you require ipc for communication use ```{ipc: true}```.

```onSignal({type: string, data: any}) => void``` - A function to handle signals from the subprocess.

###### Parameters

Object with keys:

```type: string``` - The type of signal received.

```data: any``` - The data received.

##### Returns
    
```child: ChildProcess``` - The child process.
    
```eventManager: EventEmitter``` - The event manager for the child process.
    
```request: (type: string, data: any) => Promise<{type: 'success'|'failure', data: any}>``` - A function to send a request to the subprocess and wait for a response.
    
```send: ({type: string, data: any}) => void``` - A function to send a signal to the subprocess.
    
```close: () => void``` - A function to close the subprocess.
    
```id: string``` - The id of the subprocess.


### handleMain
```handleMain(onMessage: ({type: string, data: any}) => void) => { eventManager, sendToMain }```

Creates a handler for signals to the subprocess and returns a function to send signals to the main process.

##### Inputs

```onMessage({type: string, data: any}) => void``` - A function to handle signals from the subprocess.

###### Parameters

```type: string``` - The type of signal received.

```data: any``` - The data received.

##### Returns
    
```eventManager: EventEmitter``` - The event manager for the main process.
    
```sendToMain: ({type: string, data: any}) => void``` - A function to send a signal to the main process.

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