title: Express js req.session always undefined
body: <p>I used Express Node.js to make login page with SQL server and I want to use session. Here's my code:</p>
  
  <pre><code>/**
   * Module dependencies.
   */
  
  var express = require('express');
  var routes = require('./routes');
  var user = require('./routes/user');
  var admin = require('./routes/admin');
  var http = require('http');
  var path = require('path');
  var bodyParser = require('body-parser');
  var session = require('express-session');
  var async = require("async");
  var edge = require('edge');
  var cookieParser = require('cookie-parser');
  
  
  var app = express();
  
  // all environments
  app.set('port', process.env.PORT || 3030);
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  
  
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.json());
  app.use(bodyParser.urlencoded({extended:true}));
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(require('stylus').middleware(path.join(__dirname, 'public')));
  app.use(express.static(path.join(__dirname, 'public')));
  app.use(express.static(path.join(__dirname, 'assets')));
  app.use(express.cookieParser());
  app.use(express.session({
      cookieName: 'session',
      secret: 'dgjdjdfjfjhhytjhd',
      duration: 30 * 60 * 1000,
      sctiveDuration: 50 * 60 * 1000,
      cookie: { maxAge: 24 * 60 * 60 * 1000 }
  }));
  
  
  // development only
  if ('development' == app.get('env')) {
      app.use(express.errorHandler());
  }
  
  ///////////// Routs Here .......
  app.get('/', function(req, res) {
      res.send('&lt;h5&gt;Welcome&lt;/h5&gt;&lt;a href="login" class="btn btn-default"&gt;Go To Login&lt;/a&gt;');
  });
  app.get('/login', function(req, res) {
      res.render('login');
  
  
  });
  /*======================================= Post For Login &amp; Redirect To Admin Page =====================================*/
  app.post('/login', function (req, res) {
      var username = req.body.username;
      var password = req.body.password;
      var params = {
          connectionString: "Data Source=AHMAD-HOME;Initial Catalog=nodejs;Integrated Security=True",
          source: "SELECT * FROM users WHERE username='"+ username+"' and password='"+ password+"'"
      };
      var getUsers = edge.func('sql', params);
      getUsers(null, function (error, result) {
          if (error) throw error;
          if (result) {
              if (result == '') {
                  console.log(' Empty Data From Database');
                  res.redirect('/login');
              } else {
                  req.session.userid= result;
                  res.redirect('admin');
              }
  
          } else {
              console.log('kkkkkkkkkkk');
          }
  
      });
  
  
      console.log('The UserName Is ' + username + ' And The Password Is : ' + password);
  
  });
  app.get('/admin',  function (req, res) {
      res.render('admin');
          console.log(req.session);// stack here
  });
  
  http.createServer(app).listen(app.get('port'), function () {
      console.log('Express server listening on port ' + app.get('port'));
  });
  </code></pre>
  
  <p>I always have an <code>undefined</code> session on admin page.
  I used express-session and I tried client-session before but I still the same error.</p>