text: var express = require('express');
  var exphbs = require('express-handlebars');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var bodyParser = require('body-parser');
  var routes = require('./routes/index');
  var Promise = require('bluebird');
  var codegetter = require('./routes/codegetter');
  
  function makeApp() {
    var app = express();
    // view engine setup
    var hbs = exphbs.create({
      defaultLayout: 'main',
      helpers: {
        math: function(index) {return index + 1 }
      }
    });
  
    app.engine('handlebars', hbs.engine);
    app.set('view engine', 'handlebars');
  
    app.use(logger('dev'));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(require('node-sass-middleware')({
      src: path.join(__dirname, 'public'),
      dest: path.join(__dirname, 'public'),
      indentedSyntax: true,
      sourceMap: true
    }));
    app.use('/static', express.static('public'));
  
    app.use('/', routes);
    app.use('/exercises', codegetter);
  
    // catch 404 and forward to error handler
    app.use(function(req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
    });
  
    // error handlers
  
    // development error handler
    // will print stacktrace
    if (app.get('env') === 'development') {
      app.use(function(err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
          message: err.message,
          error: err
        });
      });
    }
  
    // production error handler
    // no stacktraces leaked to user
    app.use(function(err, req, res, next) {
      res.status(err.status || 500);
      res.render('error', {
        message: err.message,
        error: {}
      });
    });
  
    return app;
  }
  
  module.exports = makeApp;
  