code: function findDirRec(dir, callback) {
        var result = path.resolve(dir, dirmod);
        fs.stat(result, function stat(err, stat) {
          if (err || !stat.isDirectory()) {
            if (lastResult == result) {
              callback(new Error('No configuration directory found.'));
              return;
            }
            lastResult = result;
            findDirRec(path.resolve(dir, '..'), callback);
          } else {
            callback(null, result);
          }
        });
      }
docs: find dirname by recursively walking up the path hierarchy