node.js - How to enumerate all the sessions in nodejs + express? -
i trying write simple nodejs server sessions , user authentication. here code:
var express = require('express'), app = express(), fs = require('fs'), passport = require('passport'), jade = require('jade'), basicauthstrategy = require('passport-http').basicstrategy, webrootdir = __dirname + '/web', templatesdir = __dirname + '/templates/'; passport.use(new basicauthstrategy( function (username, password, cb) { "use strict"; cb(null, username); } )); app.use(express.logger()); app.use(express.bodyparser()); app.use(express.cookieparser()); app.use(express.session({secret: 'd6151b7e-8997-4187-a95e-29ce08450094'})); app.use(passport.initialize()); app.use(passport.authenticate('basic', { session: false })); app.use(express.favicon()); app.use(app.router); app.use(express['static'](webrootdir)); app.use(express.errorhandler({ dumpexceptions: true, showstack: true })); app.set('view engine', 'jade'); app.engine("jade", jade.__express); app.get('/', function (req, res) { "use strict"; res.render(templatesdir + 'index', { user: req.user }); }); app.listen(8080);
now enumerate sessions created since server (i not seeking session persistency) , inspect contents. how can it?
it depends on session store you're using. session store not required provide mechanism getting stored sessions.
however, default connect in-memory session store (which should not use in production) provides .all function allow of sessions.
sessionstore.all(function(err, sessions) { // if err handle err // iterate on sessions array });
Comments
Post a Comment