Skip to content

Commit

Permalink
Add child process examples of promisify
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamingr authored Apr 19, 2017
1 parent e58940a commit 8580fb2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ replace the existing process and uses a shell to execute the command.*
If this method is invoked as its [`util.promisify()`][]ed version, it returns
a Promise for an object with `stdout` and `stderr` properties.

For example:

```js
const util = require("util");
const exec = util.promisify(require('child_process').exec);

async function lsExample() {
const {stdout, stderr} = await exec('ls');
console.log('stdout:', stdout);
console.log('stderr:', stderr);
}
lsExample();
```

### child_process.execFile(file[, args][, options][, callback])
<!-- YAML
added: v0.1.91
Expand Down Expand Up @@ -267,6 +281,16 @@ encoding, `Buffer` objects will be passed to the callback instead.
If this method is invoked as its [`util.promisify()`][]ed version, it returns
a Promise for an object with `stdout` and `stderr` properties.

```js
const util = require("util");
const execFile = util.promisify(require('child_process').execFile);
async function getVersion() {
const {stdout} = await execFile('node', ['--version']);
console.log(stdout);
}
getVersion();
```

### child_process.fork(modulePath[, args][, options])
<!-- YAML
added: v0.5.0
Expand Down

0 comments on commit 8580fb2

Please sign in to comment.