Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promisify-child-process

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promisify-child-process

seriously like the best async child process library

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

promisify-child-process

Build Status Coverage Status semantic-release Commitizen friendly

seriously like the best async child process library

Based upon child-process-async, but more thorough, because that package doesn't seem very actively maintained.

promisify-child-process provides a drop-in replacement for the original child_process functions, not just duplicate methods that return a Promise. So when you call exec(...) we still return a ChildProcess instance, just with .then() and .catch() added to make it promise-friendly.

Install

npm install --save promisify-child-process

Usage

// OLD:
const { exec, spawn, fork, execFile } = require('child_process');
// NEW:
const { exec, spawn, fork, execFile } = require('promisify-child-process');

If for any reason you need to wrap a ChildProcess you didn't create, you can use the exported promisifyChildProcess function:

const {promisifyChildProcess} = require('promisify-child-process');

async function() {
  const { stdout, stderr } = await promisifyChildProcess(
    some3rdPartyFunctionThatReturnsChildProcess()
  )
}

Examples

exec()

async function() {
  const { stdout, stderr } = await exec('ls -al');
  // OR:
  const child = await exec('ls -al', {});
  // do whatever you want with `child` here - it's a ChildProcess instance just
  // with promise-friendly `.then()` & `.catch()` functions added to it!
  child.stdin.write(...);
  child.stdout.pipe(...);
  child.stderr.on('data', (data) => ...);
  const { stdout, stderr } = await child;
}

spawn()

async function() {
  const { stdout, stderr, exitCode } = await spawn('ls', [ '-al' ]);
  // OR:
  const child = spawn('ls', [ '-al' ], {});
  // do whatever you want with `child` here - it's a ChildProcess instance just
  // with promise-friendly `.then()` & `.catch()` functions added to it!
  child.stdin.write(...);
  child.stdout.pipe(...);
  child.stderr.on('data', (data) => ...);
  const { stdout, stderr, exitCode } = await child;
}

Keywords

FAQs

Package last updated on 19 Apr 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc