here is a simple connection to use express session store, it keeps banging out this error even though the text is right from the book. I am pretty sure is has something to do with 'new MongoStore' object initialization.
var express = require('express'),
expressSession = require('express-session');
var MongoStore = require('connect-mongo/es5')(expressSession);
var sessionStore = new MongoStore({
host: '127.0.0.1',
port: '27017',
db: 'session'
});
var app = express()
.use(expressSession({
secret: 'my secret sign key',
store: sessionStore
}))
.use('/home', function (req, res) {
if (req.session.views) {
req.session.views++;
}
else {
req.session.views = 1;
}
res.end('Total views for you:' + req.session.views);
})
.use('/reset', function(req, res) {
delete req.session.views;
res.end('Cleared all your views');
})
.listen(3000);
Add URL to new MongoStore()
var sessionStore = new MongoStore({
host: '127.0.0.1',
port: '27017',
db: 'session',
url: 'mongodb://localhost:27017/demo'
});
The code in the question is from the book Beginning Node.js by Basarat Ali Syed.