Skip to content

Instantly share code, notes, and snippets.

@ChALkeR
Last active September 10, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChALkeR/983e6a8a88b7e38f9febc52939b9e0ec to your computer and use it in GitHub Desktop.
Save ChALkeR/983e6a8a88b7e38f9febc52939b9e0ec to your computer and use it in GitHub Desktop.
var express = require('express');
var session = require('express-session');
var FileStore = require('session-file-store')(session);
var store = new FileStore();
var fake = {
set: (...args) => setTimeout(() => store.set(...args), 1000),
get: (...args) => store.get(...args),
createSession: (...args) => store.createSession(...args),
touch: (...args) => store.touch(...args),
destroy: (...args) => store.destroy(...args),
length: (...args) => store.length(...args),
list: (...args) => store.list(...args),
expired: (...args) => store.expired(...args),
on: (...args) => store.on(...args)
};
var app = express();
app.use(session({
store: fake,
secret: 'secrets',
saveUninitialized: false,
resave: false
}));
app.get('/', (req, res) => {
res.send('counter: ' + req.session.bla + '<br/><a href="/increment">increment counter</a>')
});
app.get('/increment', (req, res) => {
req.session.bla = 1 + (req.session.bla || 0);
res.redirect('/');
});
app.listen(3000, () => {
console.log('Listening on port 3000');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment