title: Managing database connections in Node.js, best practices?
body: <p>I'm building an Node application which will query simple and more complex (multiple joins) queries. I'm looking for suggestions on how I should manage the mySQL connections. </p>
  
  <p>I have the following elements: </p>
  
  <ul>
  <li>server.js : Express</li>
  <li>router1.js (fictive name) : Express Router middleware</li>
  <li>router2.js (fictive name) : Express Router middleware</li>
  </ul>
  
  <pre>
  
      //this is router1
  
      router.get('/', function (req, res){
  
      connection.connect(function(Err){...});
  
        connection.query('SELECT* FROM table WHERE id = "blah"', function(err,results,fields){
          console.log(results);
        });
        ...
      connection.end();
      })
  
  </pre>
  
  <p>Should I connect to mysql everytime '/router1/' is requested, like in this example, or it's better to leave one connection open one at start up? As: <pre>connection.connect();</pre> outside of:  <pre>router.get('/',function(req,res){
  ...
  });</pre> ?</p>