text: var express = require('express');
  var path = require('path');
  var favicon = require('serve-favicon');
  var logger = require('morgan');
  var cookieParser = require('cookie-parser');
  var bodyParser = require('body-parser');
  var expressValidator = require('express-validator');
  
  var index = require('./routes/index');
  var users = require('./routes/users');
  var schedastruttura = require('./routes/schedastruttura'); //Import routes for "schedastruttura" area of site
  var compression = require('compression');
  var helmet = require('helmet');
  
  // Create the Express application object
  var app = express();
  
  app.use(helmet());
  
  //Set up mongoose connection
  
  var mongoose = require('mongoose');
  
  var mongoDB = process.env.MONGODB_URI || 'mongodb://edmdata:nettuno64@ds135592.mlab.com:35592/scheda-struttura';
  // var mongoDB = process.env.MONGODB_URI || 'mongodb://localhost:27017/Scheda-Struttura';
  mongoose.connect(mongoDB);
  var db = mongoose.connection;
  db.on('error', console.error.bind(console, 'MongoDB connection error:'));
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'pug');
  
  // uncomment after placing your favicon in /public
  //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(expressValidator() ); // Add this after the bodyParser middleware!
  app.use(cookieParser());
  
  app.use(compression()); //Compress all routes
  
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.use('/', index);              // redirect to ./calalog path
  app.use('/users', users);
  app.use('/schedastruttura', schedastruttura);     // Add schedastruttura routes to middleware chain. (under ./schedastruttura path)
  
  // 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 handler
  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 : {};
  
    // render the error page
    res.status(err.status || 500);
    res.render('error');
  });
  
  module.exports = app;
  