title: Best way to structure a mysql+nodejs+express app
body: <p>I use mysql (without sequelize) and generally create the connection in a module.export function which I then require from other files like so:</p>
  
  <pre class="lang-js prettyprint-override"><code>var db;
  module.exports={
  getConnection = function (){return new Promise(function(resolve, reject){
  // db = mysql connection stuff
  resolve(db)
  });}, 
  //other database related operations similarly
  }
  </code></pre>
  
  <p>Now, I want to separate everything for example, I want to have a userModel that will have a few database operations related to users which will just import the db connection and so on;
  But what is the optimal way of achieving this? Thanks.</p>