text: // server.js
  /**
   * Created by hasnen on 23/11/16.
   */
  
  
  // set up ======================================================================
  // get all the tools we need
  var express  = require('express');
  var app      = express();
  var port     = process.env.PORT || 8080;
  var mongoose = require('mongoose');
  var passport = require('passport');
  var flash    = require('connect-flash');
  
  var morgan       = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser   = require('body-parser');
  var session      = require('express-session');
  
  var configDB = require('./config/database.js');
  
  var http = require('http');
  var swaggerTools = require('swagger-tools');
  var jsyaml = require('js-yaml');
  var fs = require('fs');
  
  
  // swaggerRouter configuration
  var options = {
      swaggerUi: '/swagger.json',
      controllers: './app',
  };
  
  
  
  // The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
  var spec = fs.readFileSync('./app/swagger.yaml', 'utf8');
  var swaggerDoc = jsyaml.safeLoad(spec);
  
  // Initialize the Swagger middleware
  swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
      // Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
      app.use(middleware.swaggerMetadata());
  
      // Validate Swagger requests
      app.use(middleware.swaggerValidator());
  
      // Route validated requests to appropriate controller
      app.use(middleware.swaggerRouter(options));
  
      // Serve the Swagger documents and Swagger UI
      app.use(middleware.swaggerUi());
  });
  
  
  // configuration ===============================================================
  mongoose.connect(configDB.url); // connect to our database
  
  require('./config/passport')(passport); // pass passport for configuration
  
  // set up our express application
  app.use(morgan('dev')); // log every request to the console
  app.use(cookieParser()); // read cookies (needed for auth)
  app.use(bodyParser.json()); // get information from html forms
  app.use(bodyParser.urlencoded({ extended: true }));
  
  app.set('view engine', 'ejs'); // set up ejs for templating
  
  // required for passport
  app.use(session({
      secret: 'ilovescotchscotchyscotchscotch', // session secret
      resave: true,
      saveUninitialized: true
  }));
  app.use(passport.initialize());
  app.use(passport.session()); // persistent login sessions
  app.use(flash()); // use connect-flash for flash messages stored in session
  
  // routes ======================================================================
  
  require('./app/routes.js')(app, passport); // load our routes and pass in our app and fully configured passport
  
  
  // launch ======================================================================
  app.listen(port);
  console.log('The magic happens on port ' + port);
  