Wondering what’s next for npm?Check out our public roadmap! »

child-process-async

1.0.1 • Public • Published

child-process-async

The best way to override Node's child_process module w/ Promises

child-process-async 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 it to make it promise-friendly.

Install

npm install --save child-process-async

Usage

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

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;
}

Install

npm i child-process-async

DownloadsWeekly Downloads

1,019

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar