text: let express = require('express');
  let mongoose = require('mongoose');
  let logger = require('morgan');
  let cookieParser = require('cookie-parser');
  let bodyParser = require('body-parser');
  
  let config = require('config');
  let router = require('./app/routes/index');
  
  mongoose.connect(config.DB_HOST, {useMongoClient: true});
  
  let app = express();
  
  if (process.env.NODE_ENV !== 'test') {
    app.use(logger('dev'));
  }
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  
  app.use(function(req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
    res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
    next();
  });
  
  app.use('/', router);
  
  app.use(function(req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
  });
  
  app.use(function(err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
  
    res.status(err.status || 500).json({err: err});
  });
  
  module.exports = app;
  