title: Express Session Middleware
body: <p>I am doing the Coursera course on Server-Side Development and I have followed the instructions precisely.  I keep getting this error, however.  There are no relevant posts on their Discussion platform, and I cannot seem to debug because (if you see below) the trace is solely referring to files in the node_modules folder that are established upon initialization of the project as a node project.  Thus, I am stuck.  Presumably there is &quot;something&quot; wrong with my code, but since the trace is not referring to anything I coded, I am lost.  I also thought that perhaps I failed to install express, but I have tried reinstalling as per instructions in the course and that doesn't seem to solve the problem.</p>
  <p>Has anyone encountered this specific error when creating a Node.js project and, if so, what did you do to solve?</p>
  <p>Login sessions require session support. Did you forget to use <code>express-session</code> middleware?</p>
  <p>This is the app.js code:</p>
  <pre><code>var createError = require('http-errors');
  const express = require('express');
  var path = require('path');
  var cookieParser = require('cookie-parser');
  var logger = require('morgan');
  const session = require('express-session');
  var FileStore = require('session-file-store')(session);
  var passport = require('passport');
  var authenticate = require('./authenticate');
  var config = require('./config');
  
  var indexRouter = require('./routes/index');
  var usersRouter = require('./routes/users');
  var dishRouter = require('./routes/dishRouter');
  var leaderRouter = require('./routes/leaderRouter');
  var promoRouter = require('./routes/promoRouter');
  const uploadRouter = require('./routes/uploadRouter');
  
  const mongoose = require('mongoose');
  mongoose.Promise = require('bluebird');
  
  const Dishes = require('./models/dishes');
  
  const url = config.mongoUrl;
  const connect = mongoose.connect(url);
  
  connect.then((db) =&gt; {
  
    console.log('Connected correctly to the server.');
  
  }, (err) =&gt; {console.log(err); });
  
  var app = express();
  
  // Secure traffic only
  app.all('*', (req, res, next) =&gt; {
    if (req.secure) {
      return next();
    }
    else {
      res.redirect(307, 'https://' + req.hostname + ':' + app.get('secPort') + req.url);
    }
  });
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  app.use(logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded({ extended: false }));
  
  app.use(passport.initialize());
  app.use(passport.session());  // FOund this in the Forum not Given Code
  
  // Note that these two mountings occur before authentication
  app.use('/', indexRouter);
  app.use('/users', usersRouter);
  
  // Authentication is now completed
  app.use(express.static(path.join(__dirname, 'public')));
  
  // This is where the mounting occurs
  app.use('/dishes', dishRouter);
  app.use('/promotions', promoRouter);
  app.use('/leaders', leaderRouter);
  app.use('/imageUpload',uploadRouter);
  
  // catch 404 and forward to error handler
  app.use(function(req, res, next) {
    next(createError(404));
  });
  
  // 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;  
  </code></pre>
  <p>This is the index.js file:</p>
  <pre><code>    var express = require('express');
      var router = express.Router();
      
      /* GET home page. */
      router.get('/', function(req, res, next) {
        res.render('index', { title: 'Express' });
      });
  
  module.exports = router;   
  
  </code></pre>