Simple session middleware for Express
useDatabase
param in the application config you can allow express-session to use a MongoStoreSee implementation below for exact config.
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
}));
{
"session": {
"useDatabase": false,
"secret": "3G3DYBf9QkyTwNYVCX4JjDYTTbVuQmvbEDXt27aACNsZH9xSQnjGgC4DqHr9CEBC2V6GhNCjBNRATsZuA9HcRmEMUnyRspX",
"cookie": {
"maxAge": 86400000,
"secure": false,
"httpOnly": true
}
}
}
GitHub: https://github.com/expressjs/session
NPM: https://www.npmjs.com/package/express-session
Last modified | Friday, April 30, 2021, 12:00:21 PM UTC |
Last author | Colin van Eenige |
Commit ID | 4c7a701 |