DPDK Architecture  ->  Bootstrap (v3.0.5)

Express Session
>= v1.7.0

Simple session middleware for Express

Features

  • By default, express-session will use the memorystore by updating the useDatabase param in the application config you can allow express-session to use a MongoStore
  • Includes the default function with configuration from the application config

Bootstrap

Config

See implementation below for exact config.

Implementation

const session = require('express-session');

this.sessionStore = null;

if(!this.config.session.useDatabase) {
  const MemoryStore = require('memorystore')(session);
  this.sessionStore = new MemoryStore({
    checkPeriod: 86400000
  });
} else {
  const MongoStore = require('connect-mongo')(session);
  this.sessionStore = new MongoStore({
    mongooseConnection: mongoose.connection,
    collection: 'session'
  });
}

this.server.use(session({
  cookie: this.config.session.cookie,
  store: this.sessionStore,
  secret: this.config.session.secret,
  resave: false,
  saveUninitialized: true
}));

Usage

Config

{
  "session": {
    "useDatabase": false,
    "secret": "3G3DYBf9QkyTwNYVCX4JjDYTTbVuQmvbEDXt27aACNsZH9xSQnjGgC4DqHr9CEBC2V6GhNCjBNRATsZuA9HcRmEMUnyRspX",
    "cookie": {
      "maxAge": 86400000,
      "secure": false,
      "httpOnly": true
    }
  }
}

Links

GitHub: https://github.com/expressjs/session
NPM: https://www.npmjs.com/package/express-session

Last modifiedFriday, April 30, 2021, 12:00:21 PM UTC
Last authorColin van Eenige
Commit ID4c7a701