lib/index.js
function configure(opts, done) {
  delete opts._;

  opts = defaults(opts, {
    topology: process.env.MONGODB_TOPOLOGY || 'standalone'
  });

  opts = defaults(opts, {
    name: opts.topology
  });

  opts = defaults(opts, {
    logpath: untildify(
      process.env.MONGODB_LOGPATH ||
        format('~/.mongodb/runner/%s.log', opts.name)
    ),
    pidpath: untildify(process.env.MONGODB_PIDPATH || '~/.mongodb/runner/pid'),
    port: process.env.MONGODB_PORT || 27017,
    mongodBin: process.env.MONGOD_BIN || 'mongod',
    mongosBin: process.env.MONGOS_BIN || 'mongos',
    storageEngine: process.env.MONGODB_STORAGE_ENGINE,
    auth_mechanism: process.env.MONGODB_AUTH_MECHANISM || 'none',
    purge: process.env.MONGODB_PURGE || true
  });

  // MongoDB < 3.0 doesn't understand the storageEngine argument and
  // will fail to start if provided!
  if (opts.version < '3.0') {
    delete opts.storageEngine;
  }

  if (opts.topology === 'replicaset') {
    opts = defaults(opts, {
      arbiters: process.env.MONGODB_ARBITERS || 0,
      secondaries: process.env.MONGODB_SECONDARIES || 2,
      passives: process.env.MONGODB_PASSIVES || 0
    });
  }

  if (opts.topology === 'cluster') {
    opts = defaults(opts, {
      shards: process.env.MONGODB_SHARDS || 1, // -> replsets
      routers: process.env.MONGODB_ROUTERS || 1, // -> mongoses
      configs: process.env.MONGODB_CONFIGS || 1,
      shardPort: process.env.MONGODB_SHARDS_PORT || 31000, // -> replsetStartPort
      configPort: process.env.MONGODB_CONFIGS_PORT || 35000, // -> configStartPort
      arbiters: process.env.MONGODB_ARBITERS || 0,
      secondaries: process.env.MONGODB_SECONDARIES || 2,
      passives: process.env.MONGODB_PASSIVES || 0
    });
  }

  debug('Ready to process spec', opts);

  if (opts.action === 'stop') {
    return done();
  }
  async.series(
    [
      mkdirp.bind(null, opts.pidpath),
      getDbPath.bind(null, opts),
      createLogsDirectory.bind(null, opts)
    ],
    done
  );
}
function configure(opts, done) {
  delete opts._;

  opts = defaults(opts, {
    topology: process.env.MONGODB_TOPOLOGY || 'standalone'
  });

  opts = defaults(opts, {
    name: opts.topology
  });

  opts = defaults(opts, {
    logpath: untildify(
      process.env.MONGODB_LOGPATH ||
        format('~/.mongodb/runner/%s.log', opts.name)
    ),
    pidpath: untildify(process.env.MONGODB_PIDPATH || '~/.mongodb/runner/pid'),
    port: process.env.MONGODB_PORT || 27017,
    mongodBin: process.env.MONGOD_BIN || 'mongod',
    mongosBin: process.env.MONGOS_BIN || 'mongos',
    storageEngine: process.env.MONGODB_STORAGE_ENGINE,
    auth_mechanism: process.env.MONGODB_AUTH_MECHANISM || 'none',
    purge: process.env.MONGODB_PURGE || true
  });

  // MongoDB < 3.0 doesn't understand the storageEngine argument and
  // will fail to start if provided!
  if (opts.version < '3.0') {
    delete opts.storageEngine;
  }

  if (opts.topology === 'replicaset') {
    opts = defaults(opts, {
      arbiters: process.env.MONGODB_ARBITERS || 0,
      secondaries: process.env.MONGODB_SECONDARIES || 2,
      passives: process.env.MONGODB_PASSIVES || 0
    });
  }

  if (opts.topology === 'cluster') {
    opts = defaults(opts, {
      shards: process.env.MONGODB_SHARDS || 1, // -> replsets
      routers: process.env.MONGODB_ROUTERS || 1, // -> mongoses
      configs: process.env.MONGODB_CONFIGS || 1,
      shardPort: process.env.MONGODB_SHARDS_PORT || 31000, // -> replsetStartPort
      configPort: process.env.MONGODB_CONFIGS_PORT || 35000, // -> configStartPort
      arbiters: process.env.MONGODB_ARBITERS || 0,
      secondaries: process.env.MONGODB_SECONDARIES || 2,
      passives: process.env.MONGODB_PASSIVES || 0
    });
  }

  debug('Ready to process spec', opts);

  if (opts.action === 'stop') {
    return done();
  }
  async.series(
    [
      mkdirp.bind(null, opts.pidpath),
      getDbPath.bind(null, opts),
      createLogsDirectory.bind(null, opts)
    ],
    done
  );
}
function configure ( opts , done ) { delete opts . _ ; opts = defaults ( opts , { topology : process . env . MONGODB_TOPOLOGY || 'standalone' } ) ; opts = defaults ( opts , { name : opts . topology } ) ; opts = defaults ( opts , { logpath : untildify ( process . env . MONGODB_LOGPATH || format ( '~/.mongodb/runner/%s.log' , opts . name ) ) , pidpath : untildify ( process . env . MONGODB_PIDPATH || '~/.mongodb/runner/pid' ) , port : process . env . MONGODB_PORT || 27017 , mongodBin : process . env . MONGOD_BIN || 'mongod' , mongosBin : process . env . MONGOS_BIN || 'mongos' , storageEngine : process . env . MONGODB_STORAGE_ENGINE , auth_mechanism : process . env . MONGODB_AUTH_MECHANISM || 'none' , purge : process . env . MONGODB_PURGE || true } ) ; // MongoDB < 3.0 doesn't understand the storageEngine argument and // will fail to start if provided! if ( opts . version < '3.0' ) { delete opts . storageEngine ; } if ( opts . topology === 'replicaset' ) { opts = defaults ( opts , { arbiters : process . env . MONGODB_ARBITERS || 0 , secondaries : process . env . MONGODB_SECONDARIES || 2 , passives : process . env . MONGODB_PASSIVES || 0 } ) ; } if ( opts . topology === 'cluster' ) { opts = defaults ( opts , { shards : process . env . MONGODB_SHARDS || 1 , // -> replsets routers : process . env . MONGODB_ROUTERS || 1 , // -> mongoses configs : process . env . MONGODB_CONFIGS || 1 , shardPort : process . env . MONGODB_SHARDS_PORT || 31000 , // -> replsetStartPort configPort : process . env . MONGODB_CONFIGS_PORT || 35000 , // -> configStartPort arbiters : process . env . MONGODB_ARBITERS || 0 , secondaries : process . env . MONGODB_SECONDARIES || 2 , passives : process . env . MONGODB_PASSIVES || 0 } ) ; } debug ( 'Ready to process spec' , opts ) ; if ( opts . action === 'stop' ) { return done ( ) ; } async . series ( [ mkdirp . bind ( null , opts . pidpath ) , getDbPath . bind ( null , opts ) , createLogsDirectory . bind ( null , opts ) ] , done ) ; }
Populate `opts` as specified by environment specifies or defaults.

TODO (imlucas): Document options.

@param {Object} opts - user specified options
@param {Function} done - callback
@api private
Populate opts as specified by environment specifies or defaults .