title: Express creating new session for each request
body: <p>Express-session is creating a new session (new sessionID) for new request. And it happens intermittently, for example sometimes for first 3-4 hits it will work fine and keep using same existing session and on 4th hit it will create a new one, Sometimes it will create new session on first request itself.</p>
  
  <p>Also this Issue comes on my hosted website. It works fine on localhost.</p>
  
  <p>Things that i have already tried and are not working..</p>
  
  <ol>
  <li>Express session is created after static file routes.</li>
  <li>Express session secret and cookieParser secret are set to same.</li>
  <li>Using <code>app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));</code> for favicon.</li>
  <li>Setting very high value for max-age field while creating cookie.</li>
  </ol>
  
  <p>Below is my app.js snippet -</p>
  
  <pre><code>var passport = require('passport');
  var expressSession = require('express-session');
  var app = express();
  app.engine('hbs', hbs.express4({
    partialsDir: __dirname + '/views/partials'
  }));
  app.set('view engine', 'hbs');
  app.set('views', path.join(__dirname, 'views'));
  app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  
  app.use(express.static(path.join(__dirname, 'public')));
  var flash = require('connect-flash');
  app.use(flash());
  
  var initPassport = require('./passport/init');
  initPassport(passport);
  //app.use(bodyParser.urlencoded());
  app.use(cookieParser('mysecret'));
  app.use(expressSession({ secret: 'mysecret', name:'user', cookie: {maxAge: 60000000}}));
  app.use(passport.initialize());
  app.use(passport.session());
  </code></pre>
  
  <p>Any kind of help would be greatly appreciated. Thanks. </p>