pe

promise-exec

A simple wrap for child_process.exec which returns promise

Showing:

Popularity

Downloads/wk

29

GitHub Stars

4

Maintenance

Last Commit

5yrs ago

Contributors

2

Package

Dependencies

3

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

promise-exec

NPM version build status Test coverage

A simple wrap for child_process.exec which returns promise

Installation

$ npm install promise-exec

API

exec

It's a promise version of child_process.exec.

var exec = require('promise-exec');

exec('ls -al')
  .then(function(result) {
    console.log(result);
  })
  .catch(function(err) {
    console.error(err);
  });

exports.wrap

It's a sugar for subsequent thenable calls that makes code simpler and more elegant.

var exec = require('promise-exec').wrap;

Promise.resolve()
  .then(exec('git add .'))
  .then(exec('git commit -m "fix xxx"'))
  .then(exec('git push origin master'))
  .catch(function(err) {
    console.error(err);
  });

exports.execFile

Promise version of executing a shell script file, just like sh test.sh.

test.sh:

touch index.txt
echo "hello" > index.txt
# comments will be ingored
cat index.txt

index.js:

var fs = require('fs');
var path = require('path');
var execFile = require('promise-exec').execFile;
var file = path.join(__dirname, './test.sh');

execFile(file)
  .then(function() {
    var txt = path.join(__dirname, 'index.txt');
    console.log(fs.existsSync(txt));  // true

    var content = fs.readFileSync(txt, { encoding: 'utf8' });
    console.log(content);  // hello\n
  })
  .catch(function(err) {
    console.error(err);
  });

Lisence

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100