index.js
function createDatabase (name) {
  var deferred = q.defer();

  // Make sure the database location exists
  ready.then(function () {
    // Check if database exists
    fs.exists(globalConfig.db.location + name + '.db.json', function (exists) {
      if(exists) return deferred.resolve();

      // If database is non-existent, simply write an empty object as placeholder
      fs.writeFile(globalConfig.db.location + name + '.db.json', '{}', function (err) {
        if(err) return deferred.reject('Database couldn\'t create table');

        return deferred.resolve();
      });
    });
  }, function () {
    deferred.reject('Database couldn\'t instantiate');
  });

  return deferred.promise;
}
function createDatabase (name) {
  var deferred = q.defer();

  // Make sure the database location exists
  ready.then(function () {
    // Check if database exists
    fs.exists(globalConfig.db.location + name + '.db.json', function (exists) {
      if(exists) return deferred.resolve();

      // If database is non-existent, simply write an empty object as placeholder
      fs.writeFile(globalConfig.db.location + name + '.db.json', '{}', function (err) {
        if(err) return deferred.reject('Database couldn\'t create table');

        return deferred.resolve();
      });
    });
  }, function () {
    deferred.reject('Database couldn\'t instantiate');
  });

  return deferred.promise;
}
function createDatabase ( name ) { var deferred = q . defer ( ) ; // Make sure the database location exists ready . then ( function ( ) { // Check if database exists fs . exists ( globalConfig . db . location + name + '.db.json' , function ( exists ) { if ( exists ) return deferred . resolve ( ) ; // If database is non-existent, simply write an empty object as placeholder fs . writeFile ( globalConfig . db . location + name + '.db.json' , '{}' , function ( err ) { if ( err ) return deferred . reject ( 'Database couldn\'t create table' ) ; return deferred . resolve ( ) ; } ) ; } ) ; } , function ( ) { deferred . reject ( 'Database couldn\'t instantiate' ) ; } ) ; return deferred . promise ; }
Checks for existence of a database, creates if non-existent

@param  {string} name Name of database to open
@return {promise} Denotes existence of database
Checks for existence of a database creates if non - existent