req.session in express-session not persisting
<p>I have the following code:</p>

<pre><code>var express = require('express');
var cookieParser = require('cookie-parser');
var http = require('http')
var app = express();
app.use(cookieParser());
var session = require('express-session');
app.use(session({
    resave: false,
    saveUninitialized: true,
    secret: 'sdlfjljrowuroweu',
    cookie: { secure: true }
}));

app.get('/test', test);
function test(req, res) {
    var sess = req.session;
    console.log('before', sess);
    if (sess.views) {
        sess.views++
        req.session.save();
        res.setHeader('Content-Type', 'text/html')
        res.write('&lt;p&gt;views: ' + sess.views + '&lt;/p&gt;')
        res.write('&lt;p&gt;expires in: ' + (sess.cookie.maxAge / 1000) + 's&lt;/p&gt;')
        res.end();
    } else {
        sess.views = 1;
        req.session.save();
        res.end('welcome to the session demo. refresh!')
    }
    console.log('after', sess);
    return;
}

var server = http.createServer(app);
server.listen(8181);
</code></pre>

<p>And reloading the page, I just keep getting the view count 0 message. </p>

<p>Checking the console, this is the output every time:</p>

<pre><code>before { cookie: 
   { path: '/',
     _expires: null,
     originalMaxAge: null,
     httpOnly: true,
     secure: true } }
after { cookie: 
   { path: '/',
     _expires: null,
     originalMaxAge: null,
     httpOnly: true,
     secure: true },
  views: 1 }
</code></pre>

<p>So it doesn't seem to be saving at all</p>