jeffreyveon jeffreyveon - 1 year ago 149
Node.js Question

Connect session middleware - regenerate vs reload

I am trying to get a hang of Connect's Session middleware, and I would like to know the difference between: Session.regenerate() vs Session.reload().

Specifically, I checked the docs, and no explanation was given about what session reload actually does. Similarly, I am also confused about method. Any help greatly appreciated!

Answer Source

Comparing the source code for the 2 functions:


Store.prototype.regenerate = function(req, fn){
  var self = this;
  this.destroy(req.sessionID, function(err){



defineMethod(Session.prototype, 'reload', function reload(fn) {
  var req = this.req
    , store = this.req.sessionStore;
  store.get(, function(err, sess){
    if (err) return fn(err);
    if (!sess) return fn(new Error('failed to load session'));
    store.createSession(req, sess);
  return this;

I read it as "get the session if it exists or create one" vs "destroy the previous and give me a new one".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download