var session = require('express-session'); const MongoStore = require('connect-mongo')(session);
app.use(session({ key: 'ERP.Session', secret: '310E56DD8E7C', resave:true, saveUninitialized:true, store: new MongoStore({ url: 'mongodb://localhost/ERP' }) }));
Setting Session Variables
req.session.name = 'Napoleon'; req.session['primary skill'] = 'Dancing';
Reading Session Variables
var name = req.session.name; var primary_skill = req.session['primary skill'];
Updating Session Variables
req.session.skills.push('Baking'); req.session.name = 'Pedro';
Deleting Session Variables
delete req.session.name delete req.session['primary skill'];
Deleting a Session
req.session.destroy();
req.session.destroy(function() { res.send('Session deleted'); });
References
http://expressjs-book.com/index.html%3Fp=128.html
https://github.com/expressjs/session
https://github.com/jdesboeufs/connect-mongo