server.js
// this function connects to our database, then starts the server
this function connects to our database, then starts the server
this function connects to our database then starts the server
function runServer(databaseUrl = DATABASE_URL, port = PORT) {
  return new Promise((resolve, reject) => {
    mongoose.connect(databaseUrl, err => {
      if (err) {
        return reject(err);
      }
      server = app.listen(port, () => {
        console.log(`Your app is listening on port ${port}`);
        resolve();
      })
        .on('error', err => {
          mongoose.disconnect();
          reject(err);
        });
    });
  });
}
function runServer ( databaseUrl = DATABASE_URL , port = PORT ) { return new Promise ( ( resolve , reject ) => { mongoose . connect ( databaseUrl , err => { if ( err ) { return reject ( err ) ; } server = app . listen ( port , ( ) => { console . log ( ` ${ port } ` ) ; resolve ( ) ; } ) . on ( 'error' , err => { mongoose . disconnect ( ) ; reject ( err ) ; } ) ; } ) ; } ) ; }
this function connects to our database, then starts the server
this function connects to our database then starts the server