#!/usr/local/bin/node Q = require('q'); var childProcess = require('child_process'), ls; function dumper(content){ console.log(JSON.stringify(content)); } function go_big(){ var promise_chain = Q.fcall(function(){}); var sync_operations = [ "ls | grep \"[^a-z]\"", "cat" ]; sync_operations.forEach(function(async_op) { var promise_link = function() { var deferred = Q.defer(); child_process.exec(async_op, function(error, stdout, stderr) { var result = { "error" : error, "stdout" : stdout, "stderr" : stderr }; deferred.resolve(result); }); return deferred.promise; }; // add the link onto the chain promise_chain = promise_chain.then(promise_link); }); return promise_chain } go_big().then(function(result){ dumper(result) } ) //didn't quite get this one //https://coderwall.com/p/ijy61g