title: ReferenceError: session is not defined with ('connect-mongo')(session),
body: <p>I'm trying to add <a href="https://github.com/jdesboeufs/connect-mongo" rel="nofollow noreferrer">connect-mongo</a> in order to save sessions when nodeJS restarts.</p>
  
  <p>Per the documentation I added: 
  <code>MongoStore = require('connect-mongo')(session),</code> </p>
  
  <p>and in my <code>require('express-session')</code> I added</p>
  
  <pre><code>store: new MongoStore({
      url: mongooseDB,
      touchAfter: 24 * 3600
  })
  </code></pre>
  
  <p>and commented out <code>app.use(passport.session());</code></p>
  
  <p>I'm getting an error: ReferenceError: session is not defined which is pointed to <code>MongoStore = require('connect-mongo')(session),</code></p>
  
  <p>I've added my app.js file for reference. How can I fix this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>'use strict';
  const express = require('express'),
      app = express(),
      bodyParser = require('body-parser'),
      mongoose = require('mongoose'),
      MongoStore = require('connect-mongo')(session),
      passport = require('passport'),
      flash = require('connect-flash'),
      LocalStrategy = require('passport-local'),
      methodOverride = require('method-override'),
      logger = require('morgan'),
      cookieParser = require('cookie-parser'),
      User = require('./models/user'),
      faker = require('faker'),
      path = require('path');
  
  const indexRoute = require('./routes/index'),
      usersRoute = require('./routes/users'),
      giftsRoute = require('./routes/gifts.js'),
      searchRoute = require('./routes/search');
  
  const mongooseDB = 'mongodb://localhost/giftcashing';
  
  mongoose.connect(mongooseDB);
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  
  app.use(logger('dev'));
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(cookieParser());
  app.use(express.static(path.join(__dirname, 'public')));
  app.use('/bower_components',  express.static(__dirname + '/bower_components'));
  app.use(methodOverride("_method"));
  app.use(flash());
  
  app.use(require('express-session')({
      secret: 'anything',
      resave: false,
      saveUninitialized: false,
      store: new MongoStore({
          url: mongooseDB,
          touchAfter: 24 * 3600
      })
  }));
  
  // PASSPORT CONFIGURATION
  app.use(passport.initialize());
  // app.use(passport.session());
  
  // use static authenticate method of model in LocalStrategy
  passport.use(new LocalStrategy(User.authenticate()));
  
  // use static serialize and deserialize of model for passport session support
  passport.serializeUser(User.serializeUser());
  passport.deserializeUser(User.deserializeUser());
  
  app.use(function (req, res, next) {
      res.locals.currentUser = req.user;
      res.locals.error = req.flash('error');
      res.locals.success = req.flash('success');
      next();
  });
  
  // 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;
      // render the error page
      res.status(err.status || 500);
      res.render('error');
  });
  
  app.use('/', indexRoute);
  app.use('/users', usersRoute);
  app.use('/gifts', giftsRoute);
  app.use('/search', searchRoute);
  
  module.exports = app;</code></pre>
  </div>
  </div>
  </p>