title: Session using NodeJS and Express 4.x (req.session undefined)
body: <p>First of all sorry my bad English. I'm studying and I'm doing an academic project and came across a problem. I can not recall a session variable.</p>
  
  <p>package.json</p>
  
  <pre><code>  "dependencies": {
      "body-parser": "^1.7.0",
      "ejs": "~1.0.0",
      "express": "^4.8.7",
      "express-session": "^1.11.3",
      "ini": "^1.3.4",
      "mysql": "^2.8.0",
      "winston": "^1.0.1"
  }
  </code></pre>
  
  <p>server.js</p>
  
  <pre><code>var express = require('express');
  var session = require('express-session');
  var app = express();
  ...
  require('./router/main')(app, language, connection, logger);
  
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.engine('html', require('ejs').renderFile);
  app.use(express.static(__dirname + '/public'));
  app.use(session({
      secret: 'pecuniamsekretsession',
      resave: false,
      saveUninitialized: true,
      cookie: { secure: true }
  }));
  </code></pre>
  
  <p>main.js</p>
  
  <pre><code>module.exports = function(app, languageItems, connection, logger) {
      app.post('/', require('../router/login.js')(languageItems, connection, logger)); 
      app.get('/', require('../router/login.js')(languageItems, connection, logger));
  }
  </code></pre>
  
  <p>login.js</p>
  
  <pre><code>module.exports = function (language, connection, logger) {
  
      var routerTemplateLogin = function (req, res) {
          var utils = require('../utils/utils');
          var util = new utils.Util;  
  
          // It does not work  :-(
          logger.debug(req.session); 
  
          req.on('data', function(data) {
              var arrayPost = util.postDataToArray(data);
          });     
  
          res.render('pages/login.ejs', {
              lang: language
          });
      }
  
      return routerTemplateLogin;
  }
  </code></pre>
  
  <p>In login.js see <code>// It does not work  :-(</code>. Full project in <a href="https://github.com/braulioti/pecuniam" rel="nofollow">https://github.com/braulioti/pecuniam</a></p>
  
  <p>Thanks</p>