Memcached Cloud session store with express-session to preserve sessions off-server


Fri May 08 2020 23:05:13 GMT+0000 (Coordinated Universal Time)

Saved by @mishka #nodejs

var express = require("express");
var app = express();
const session = require('express-session');
var MemcachedStore = require('connect-memjs')(session);

// configure sessions
var store = new MemcachedStore({servers: [process.env.MEMCACHEDCLOUD_SERVERS], username: process.env.MEMCACHEDCLOUD_USERNAME, password: process.env.MEMCACHEDCLOUD_PASSWORD});
app.use(session({ secret: 'keyboard cat',
   resave: true,
   saveUninitialized: true,
   cookie: { secure: true }, 
   store: store

Connect-memjs: Memcached Cloud: