Synchronous Node shell commands

While working on a deployment script, I had a series of shell commands that needed to be run in sequence. I looked around quite a while for an elegant way of doing that but no one seemed to have one until I stumbled upon this site which had an extremely simple way to do so using the Async library. I modified it a little bit to show the output of the shell command for use in logging. excerpt_separator

 1 var async = require('async');
 2 
 3   function execSync() {
 4 
 5     async.series([
 6       execFn('pwd'),
 7       execFn('ls -l'),
 8       execFn('ps -a')
 9     ]);
10   }
11 
12   var execFn = function(cmd, dir) {
13     return function(cb) {
14       console.log('EXECUTING: ' + cmd);
15       exec(cmd, function(error, stdout, stderr) {
16         sys.print("$" + stdout);
17         sys.print("stderr: " + stderr)
18         cb();
19       });
20     }
21   }
22 
23   execSync();