title: Right nodejs+express+mongodb application architecture
body: <p>I'm new to nodejs (and js itself) and I'm trying to figure out what is the best way to combine mongodb and express. In some npm-modules I saw a construction, where middleware set a db-property in request object, which contained current database connection. Something like this:</p>
  
  <pre><code>app.use(function (req, res, next)) {
      /* creating connection */
      req.db = createdConnection;
      next();
  });
  </code></pre>
  
  <p>I find its very convenient to make the whole structure of the project in similar req-modifying manner, for example:</p>
  
  <pre><code>app.use(function (req, res, next)) {
      /* lots of requires, which provide necessary functionality */
      req.UsersModule = usersModule;
      req.ArticlesModule = articlesModule;
      /* and so on, plenty of them */
      next();
  });
  </code></pre>
  
  <p>But I'm not sure this is a good idea. For example, having non-request-related functionality in request object is semantically awful. More than that, I can't predict could this way break something important in the future or not. Could you help me to resolve such a predicament, please?</p>