title: Object method in Express-Session
body: <p>Currently I'm trying to link an object with an express session.<br>
  There is my code :</p>
  
  <pre><code>var express = require('express');
  var session = require('express-session');
  
  // I have an object named "engine", which is a fake SQL Object connection (for example)
  // this is my engineFactory (which return an engine when function "giveMeObject" is called).
  var engineFactory = require('./tools/engineFactory');
  var eF = new engineFactory();
  
  // create my app
  var port = 3030;
  var app = express();
  
  app.use(session({
      secret: "secret"
  }));
  
  app.get('/', function(req, res) {
      // Req.session.engine will contains an SQL connection
      req.session.engine = eF.giveMeObject();
      res.send('object gived : ' + req.session.engine); // return "object gived : [object Object]", so ok.
  });
  
  app.get('/session', function(req, res) {
      // Here I verify if my engine still exists
      res.send("Coming From Session: " + req.session.engine); // return "Coming From Session: [object Object]" so, ok.
  });
  
  app.get('/session-test', function(req, res) {
      // Here I 
      res.send(Object.getOwnPropertyNames(req.session.engine)); // return ["attributeA","attributeB"], so where is my connectMe() ?
      req.session.engine.connectMe(); // error : "req.session.engine.connectMe is not a function"
  });
  
  app.listen(port);
  console.log('app listen to ' + port);
  </code></pre>
  
  <p>So, my problem is, I wanna link an object to a session (typically a SQL connection object). And re-use this object "everywhere" to execute queries, etc.
  But when I try to use my function I have the following error message :<br>
  "req.session.engine.connectMe is not a function"  </p>
  
  <p>Just for information, my engine object, and the engine factory code :<br>
  <strong>Engine</strong></p>
  
  <pre><code>function engine(){
      this.attributeA = "aaa";
      this.attributeB = "bbb";
  };
  
  engine.prototype.connectMe = function(){
      return this.attributeA + this.attributeB;
  };
  
  module.exports = engine;
  </code></pre>
  
  <p><strong>EngineFactory</strong></p>
  
  <pre><code>var engine = require('./engine');
  
  function engineFactory() {
  
  };
  
  engineFactory.prototype.giveMeObject = function() {
      return new engine;
  };
  
  module.exports = engineFactory;
  </code></pre>
  
  <p>As I said, the goal is to link a SQL connection with a user session. The connection is gived to the user, then, the app re-use the user's connection to ask queries to the database (about that, I know that the pool connection pattenr is better, but this is a requirement of this project for many reasons).<br>
  But currently I can't re-use the object's method...</p>
  
  <p>Thanks for the help.  </p>