Child Process
A small wrapper around the Node.js ChildProcess.spawn
function that provides access to not only the child process, but a wrapping promise to use in your JavaScript logic.
Getting Started
Installation
npm install --save @figliolia/child-process
yarn add @figliolia/child-process
Basic Usage
import { ChildProcess } from "@figliolia/child-process";
const CP = new ChildProcess(
"some shell command"
);
await CP.handler;
CP.process.on("something", () => {});
const { stdout, stderr } = await ChildProcess.execute("your command");
Advanced Usage
It's fairly common to require the management of multiple sub-process when building complex applications such as development environments, CI's, and more.
This library provides a means for handling multiple child processes as well as binding to kill exit signals that may cause an underlying application to fail.
import { ChildProcess } from "@figliolia/child-process";
class MyApplication {
public static run() {
const shells = this.bootStuffUp();
ChildProcess.bindExits(shells);
return Promise.all(shells.map(CP => CP.handler));
}
private static bootStuffUp() {
return [
new ChildProcess(
"some shell command"
),
new ChildProcess(
"another shell command"
),
new ChildProcess(
"perhaps another shell command"
),
]
}
}