title: How to provide a mysql database connection in single file in nodejs
body: <p>I need to provide the mysql connection for modules. I have a code like this.</p>
  
  <pre><code>var express = require('express'),
  app = express(),
  server = require('http').createServer(app);
  
  var mysql      = require('mysql');
  var connection = mysql.createConnection({
      host     : '127.0.0.1',
      user     : 'root',
      password : '',
      database    : 'chat'
  });
  
  connection.connect(function(err) {
      if (err) {
          console.error('error connecting: ' + err.stack);
          return;
      }
  });
  
  app.get('/save', function(req,res){
      var post  = {from:'me', to:'you', msg:'hi'};
      var query = connection.query('INSERT INTO messages SET ?', post, function(err, result) {
          if (err) throw err;
      });
  });
  
  server.listen(3000);
  </code></pre>
  
  <p>But how we provide one time mysql connection for all the modules.</p>