title: MongoDB connection error nodejs express mongoose
body: <p>im a beginner and trying to test some basic conection to MongoDB with node and express and mongoose and cannot find why is returning as undifined</p>
  <p>Im using a dotenv module to use an env variable, any advice</p>
  <p>MongooseError: The <code>uri</code> parameter to <code>openUri()</code> must be a string, got &quot;undefined&quot;. Make sure the first parameter to <code>mongoose.connect()</code>
  or <code>mongoose.createConnection()</code> is a string.</p>
  <p>This is my code</p>
  <pre><code>// index.js
  
  import app from './app'
  import './database'
  
  app.listen(app.get('port'))
  console.log('Greetings from express')
  </code></pre>
  <pre><code>// database.js
  
  import mongoose from &quot;mongoose&quot;;
  import config from './config'
  
  (async () =&gt; {
      const db = await mongoose.connect(config.mongodbURL, {
          useNewUrlParser: true,
          useUnifiedTopology: true,
      });
      console.log('Database connected to:', db.connection.name);
  })();
  </code></pre>
  <pre><code>// config.js
  import { config } from &quot;dotenv&quot;;
  config();
  
  export default {
      mongodbURL: process.env.MONGODB_URI,
  };
  </code></pre>
  <pre><code>// .env
  MONGODB_URI = mongodb://localhost/tasksapi
  </code></pre>