I'm having a weird problem with nodejs and sessions. I have traced the problem down to session.save function,
TypeError: Cannot read property 'sessionStore' of undefined
at Session.save (C:\Program Files\nodejs\node_modules\express\node_modules\connect\lib\middleware\session\session.js:65:11);
//Code in connect session module where this.req gets its value
var Session = module.exports = function Session(req, data) {
Object.defineProperty(this, 'req', { value: req });
Object.defineProperty(this, 'id', { value: req.sessionID });
if ('object' == typeof data) utils.merge(this, data);
console.log("SESSION CREATED", typeof this.req, "VS" , typeof req);
//outputs SESSION CREATED undefined VS object
};
//The session.save function, here the this.req is undefined and it causes the error
Session.prototype.save = function(fn){
this.req.sessionStore.set(this.id, this, fn || function(){});
return this;
};
What could be causing this?
quick edit:
This problem only occurs if i require an external api(box2d) file. var Box2D = require('./box2d.js'); That file works since it came with a working demo, and it worked with my code too, but then after restarting node...for some reason i breaks the sessions. Sockets still work.
The file is here (shortened google docs) box2D I searched it for keywords that might conflict but nothing suspicious shows up. That file is fairly large...could that be a problem ?