forked from gx0r/connect-session-knex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
38 lines (31 loc) · 886 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const express = require("express"); // Express 4
const app = express();
const session = require("express-session");
const KnexSessionStore = require("connect-session-knex")(session);
const store = new KnexSessionStore(/* options here */); // defaults to a sqlite3 database
app.use(
session({
secret: "keyboard cat",
cookie: {
maxAge: 30000 // 30 seconds for testing
},
store: store
})
);
var count = 0;
app.use("/", function(req, res, next) {
var n = req.session.views || 0;
req.session.views = ++n;
res.end(n + " views");
});
app.listen(3000);
setInterval(function() {
store.length().then(function(length) {
console.log("There are " + JSON.stringify(length) + " sessions");
});
}, 2000);
setInterval(function() {
store.clear().then(function(length) {
console.log("Cleared " + JSON.stringify(length) + " sessions");
});
}, 30000);