Socket
Socket
Sign inDemoInstall

@figliolia/child-process

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @figliolia/child-process

A wrapper around the node.js spawn function providing a promise and graceful exiting


Version published
Maintainers
1
Install size
9.24 kB
Created

Readme

Source

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
# or
yarn add @figliolia/child-process

Basic Usage

import { ChildProcess } from "@figliolia/child-process";

const CP = new ChildProcess(
  "some shell command"
);

// Await the completion of your command
await CP.handler;

// Use the raw child process in your code
CP.process.on("something", () => {});

// If you do not need access to the underlying child process, 
// but instead wish to have just a promise with stdio access
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();
		// Kill each shell if the parent process receives
		// a kill signal or uncaught exception
		ChildProcess.bindExits(shells);
		// Await the completion of all commands
		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"
			),
		]
	}
}

Keywords

FAQs

Last updated on 13 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc