This is exactly what I was looking for, but could you give a more detailed example with async/await…
Wesley Mostien

Sure thing.

So exec isn’t a perfect model for this because the callback contains 3 arguments and node-style callbacks should have 2 (err, data), etc. But it still works if you don’t mind ignoring the 3rd argument.

But you can translate this code:

exec(['ls', '-lha'], function(err, out, code) {
if (err instanceof Error)
throw err;

into this:

import exec from 'exec'
import promisify from './lib/promisify'
const execP = promisify(exec)
execP(['ls', '-lha'])
.then(out => process.stdout.write(out))
.catch(err => process.stderr.write(err));