title: nodejs require cannot find name
body: <p>I am trying to return an instance of <code>connection</code> from an import.</p>
  <pre><code>const express = require('express')
  const bodyParser = require('body-parser')
  
  require(&quot;dotenv&quot;).config();
  
  db = require('./services/db_service').db_connection() &lt;---- here
  
  var app = express();
  app.use(bodyParser.json());
  
  app.get('/customers' , (req, res) =&gt; {
      db.query('SELECT * FROM customers', (err, rows, fields) =&gt; {
          if (!err)
              res.send(rows);
          else
              console.log(err);
      })
  } );
  
  app.listen(process.env.PORT, function () {
    console.log(`Example app listening on port ${process.env.PORT}!`)
  })
  </code></pre>
  <p>In <code>/services/db_service.ts</code> file:</p>
  <pre><code>export const db_connection = function () {
      const { HOST, USER, PASSWORD, DATABASE } = process.env
      var mysql = require('mysql');
  
      var con = mysql.createConnection({
        host: HOST,
        user: USER,
        password: PASSWORD,
        database: DATABASE,
        multipleStatements: true
      });
  
      con.connect(function(err) {
        if (err) throw err;
        console.log(&quot;Connected!&quot;);
      });
  
      return con; &lt;--- return this
  
  }
  </code></pre>
  <p>But I get this error:</p>
  <pre><code>index.ts:6:1 - error TS2304: Cannot find name 'db'.
  
  db = require('./services/db_service').db_connection()
  </code></pre>