title: req.session undefined and req.session.user_id not working
body: <p>I am using Express and node for the session management with https. I want to create a session using express so that authentication and the session is made before the redirection to the static files in the public folder. Previously i was having a problem <a href="https://stackoverflow.com/questions/21051252/trouble-using-express-session-with-https">Trouble using express.session with https</a>
  But it was solved by including path in the express.session as /public but now my req.session is showing as undefined but in the browser there is connect.sid cookie present</p>
  
  <p>The app.js is :</p>
  
  <pre><code>var express = require('express')TypeError: Cannot set property 'user_id' of undefined at /opt/expressjs/app.js:59:24 at callbacks;
  var http = require('http');
  var https = require('https');
  var fs = require('fs');
  var mongo = require('mongodb');
  var monk = require('monk');
  var db = monk('localhost:27017/svgtest1');
  var options = {
    key: fs.readFileSync('privatekey.pem'),
    cert: fs.readFileSync('certificate.pem')
  };
  
  var app = express();
  
  app.use(express.static(__dirname + '/public'));
  app.use(express.urlencoded());
  app.use(express.json());
  app.use(express.cookieParser());
  app.use(express.session({cookie: {  path: '/public/',httpOnly: false , maxAge: 24*60*60*1000}, secret: '1234567890QWERT'}));
  
  //middle ware to check auth
  function checkAuth(req, res, next) {
    if (!req.session.user_id) {
      res.send('You are not authorized to view this page');
    } else {
      next();
    }
  }
  
  
  app.get('/', function(req, res) {
    console.log('First page called');
    res.redirect('loginform.html');
    console.log('redirected');
    res.end();
  });
  
  app.post('/login', function(req, res) {
    console.log('login called');
    var usrfield = req.body.usrfield;
    var passfield = req.body.passfield;
  
      console.log(req.session);
  
  
  // Play with the username and password
  
          if (usrfield == 'kk' &amp;&amp; passfield == '123') {
               req.session.user_id = 'xyz';
          res.redirect('svg-edit.html');
        } else {
          res.send('Bad user/pass');
        }
  
  
          console.log(usrfield);
          console.log(passfield);
          res.end();
      });
  </code></pre>
  
  <p>Client Side : </p>
  
  <pre><code>&lt;html&gt;
  
  &lt;style media="screen" type="text/css"&gt;
  @import url("css/loginform_styles.css");
   &lt;/style&gt;
  
      &lt;head&gt;
              &lt;script type="text/javascript" src="annotationTools/js/md5.js" &gt;&lt;/script&gt;
              &lt;script&gt;
  
                  function validateForm()
                  {
                      var usrnamefield=document.forms["loginform"]["usrfield"].value;
                      var passwrdfield=document.forms["loginform"]["passfield"].value;
  
                      if ((usrnamefield==null || usrnamefield=="")||(passwrdfield==null || passwrdfield==""))
                        {
                          document.getElementById('valueerrorlayer').innerHTML ='Username or password field is empty';
                          //document.forms["loginform"]["errorshow"].innerHtml = 'username or password empty';
                        return false;
                        }
                      else return true;
                  }
              &lt;/script&gt;
  
      &lt;/head&gt;
  
      &lt;body&gt;
  
  
      &lt;form name="loginform" id="loginform" action="https://localhost:8888/login" method="post" onsubmit="return validateForm()"&gt;
          &lt;div id = "content" align = "center"&gt;
  
              &lt;p align="center"&gt;&lt;font size="7"&gt;LabelMe Dev&lt;/font&gt;&lt;/p&gt; 
              &lt;br /&gt;
              &lt;br /&gt;
  
              &lt;label&gt; Please Enter the &lt;b&gt;&lt;i&gt;Username&lt;/i&gt;&lt;/b&gt;&lt;/label&gt;
              &lt;br /&gt;
              &lt;br /&gt;
  
              &lt;input type="text"  name = "usrfield" id = "usrfield" onkeydown="if (event.keyCode == 13) document.getElementById('btnSearch').click()"/&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;br /&gt;
  
              &lt;label&gt; Please Enter the &lt;b&gt;&lt;i&gt;Password&lt;/i&gt;&lt;/b&gt;&lt;/label&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;input type="password"  name = "passfield" id = "passfield" onkeydown="if (event.keyCode == 13) document.getElementById('btnSearch').click()"/&gt;
              &lt;br /&gt;
              &lt;br /&gt;
              &lt;br /&gt;
  
              &lt;i&gt;&lt;p id='valueerrorlayer' style="color:red;"&gt; &lt;/p&gt;&lt;/i&gt;
  
              &lt;input type="submit" value="Submit"/&gt;
          &lt;/div&gt;
      &lt;/form&gt;     
      &lt;/body&gt;
  
  
  
  
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>The problem</strong> is that <code>console.log(req.session);</code> gives undefined so the <code>req.session.user_id = 'xyz';</code> also not works and error <code>'TypeError: Cannot set property 'user_id' of undefined at /opt/expressjs/app.js:59:24 at callbacks'</code> comes.
  I have gone through many questions but was not able to figure out. </p>
  
  <p>My website is static and all the *.html locates in the public directory </p>