title: TypeError: Cannot destructure property `db` of 'undefined' or 'null'
body: <p>I am getting a TypeError in my variable assignment for mongodb connection. Is there a workaround for this?</p>
  
  <pre><code>//server.js
  var mongoose = require('mongoose');
  var config = require('./config');
  
  var { db: {user,pass,host,port,name } } = config;
  
  var connectionString = `mongodb://${user}:${pass}@${host}:${port}/${name}`;
  
  mongoose.connect(connectionString, { useMongoClient: true });
  </code></pre>
  
  <p>Error </p>
  
  <pre><code>C:\mean\webguidv1\server.js:65
    db: {
    ^
  
  TypeError: Cannot destructure property `db` of 'undefined' or 'null'.
  </code></pre>
  
  <p>Here is my config.js file </p>
  
  <pre><code>// config.js
  var env = process.env.NODE_ENV; // 'dev' or 'test'
  
  var dev = { app: { port: 3000 }, db: {user: '', pass: '', host: '', port: , name: '' }};
  
  var test = { app: { port: 3000 }, db: {user: '', pass: '', host: '', port: , name: '' }};
  
  var config = { dev, test };
  
  module.exports = config[env];
  </code></pre>