title: Why is it showing connection not defined?
body: <p>I'm trying to use <code>connection</code> from a <strong>connection.js</strong> file and use it in different file <strong>webFrontend.js</strong> using <code>exports</code> object. Now what I get on running server is:</p>
  
  <pre><code>{
    "Result": "undefinedThis is result"
  }
  </code></pre>
  
  <p>That means <code>connection</code> is not defined. Why is it happening? <code>connection</code> is working fine if <code>getConnection</code> is created in same (<strong>webFrontend.js</strong>) file, but the problem is when I use <code>getConnection</code> in same exports function in <strong>connection.js</strong> hence the <code>connection</code> not defined error:</p>
  
  <p>Here are 2 necessary files (routes file has no problem) that explains what I'm doing:</p>
  
  <p><strong>connection.js</strong></p>
  
  <pre><code>var mysql = require('mysql');
  exports.connExport = function () {
      var connectionPool = mysql.createPool({
          host: 'localhost',
          user: 'root',
          password: '',
          database: 'rockcity_followme'
      });
      if(connectionPool) {
          connectionPool.getConnection(function (err, connection) {
              if (err) {
                  return err;
              } else {
                  return connection;
              }
          });
      }else{
          var abc="return error";
          return abc;
      }
  }
  </code></pre>
  
  <p><strong>webFrontend.js</strong></p>
  
  <pre><code>var connObj=require('../Routes/connection.js');
  var connection=connObj.connExport();
  exports.getIndivRecords= function(req, res, next){
  res.send({
      Result: connection+"This is result"
  });
      return next();
  };
  </code></pre>