How to use express-session

Comprehensive express-session code examples:

How to use express-session.session:

70
71
72
73
74
75
76
77
78
79
(session) => {
  if (session) {
    if (typeof session.session === 'string') {
      session.session = JSON.parse(session.session);
    }
    const s = session.session;
    if (this.options.touchAfter > 0 && session.lastModified) {
      s.lastModified = session.lastModified;
    }
    this.emit('get', sid);

How to use express-session.call:

36
37
38
39
40
41
42
43
44
45
 * @param {Number} [options.timeout] Session timeout (in minutes). Use a negative value to never expire.
 * @public
 */

function MemoryStore(options) {
  Store.call(this)
  this.sessions = Object.create(null)
  this.session_timers = Object.create(null)

  // set up the store

How to use express-session.Store:

How to use express-session.Cookie:

125
126
127
128
129
130
131
132
133
134
const session = request.session = {};
session.id = request.sessionID = crypto.randomBytes(32).toString('hex');
session.skey = generateSkey(sessionKey);
session.sessionKey = sessionKey;
session.userInfo = userInfo;
session.cookie = new Cookie({ maxAge }); // fake cookie to support express-session Stores

// save the session
store.set(session.id, session, (err) => {
    if (err) {

How to use express-session.lastModified:

72
73
74
75
76
77
78
79
80
81
  if (typeof session.session === 'string') {
    session.session = JSON.parse(session.session);
  }
  const s = session.session;
  if (this.options.touchAfter > 0 && session.lastModified) {
    s.lastModified = session.lastModified;
  }
  this.emit('get', sid);
  return s;
}

How to use express-session.MemoryStore:

13
14
15
16
17
18
19
20
21
22
var expressSession = require('express-session');
var bodyParser = require('body-parser');
var methodOverride = require('method-override');
var cookieParser = require('cookie-parser');

var sessionStore = new expressSession.MemoryStore();
var app = express();
var http = require('http').Server(app);

var response_options = {root: __dirname};