title: Node not exporting connection to mongodb atlas
body: <p>My connection works in general, but when I try to export the connection and use it in another module, I get the error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'collection' of undefined
  at /Users/.../meet.js:7:20</p>
  <p>here is my connection.js:</p>
  <pre><code>require('dotenv').config();
  const { MongoClient } = require(&quot;mongodb&quot;);
  
  // Replace the following with your Atlas connection string
  const url = process.env.MONGODB_ADDRESS;
  const client = new MongoClient(url);
  const dbName = &quot;MarketingScrape&quot;;
  
  async function run() {
      try {
          await client.connect();
          console.log(&quot;Connected correctly to database server&quot;);
          return client.db(dbName);
      } catch (err) {
          console.log(err.stack);
      }
  }
  
  module.exports = run;
  </code></pre>
  <p>here is meet.js:</p>
  <pre><code>require('dotenv').config();
  const db = require('./connect')
  const puppeteer = require('puppeteer');
  const ac = require(&quot;@antiadmin/anticaptchaofficial&quot;);
  let collection = null;
  db().then(c =&gt; {
      collection = c.collection('Meet')
  });
  
  (async () =&gt; {...
  </code></pre>