text: let express = require('express')
  let path = require('path')
  let favicon = require('serve-favicon')
  let logger = require('morgan')
  let cookieParser = require('cookie-parser')
  let bodyParser = require('body-parser')
  let session = require('express-session')
  let MongoStore = require('connect-mongo')(session)
  //  config file
  let config = require('./model/config')
  
  let index = require('./routes/index')
  let users = require('./routes/users')
  
  let app = express()
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'))
  app.set('view engine', 'ejs')
  
  // 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(cookieParser(config.cookie_secret))
  app.use(session({
      secret: config.cookie_secret,
      cookie: 365 * 3600 * 24 * 1000,//one year
      store: new MongoStore({
          url: `mongodb://${config.db_url_local}`
      })
  }))
  app.use(express.static(path.join(__dirname, 'public')))
  app.use('/', index)
  app.use('/users', users)
  
  // catch 404 and forward to error handler
  app.use(function (req, res, next) {
      let 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
  