title: Setting Environment Variables from different files in node.js?
body: <p>I have two different Environment development and production</p>
  
  <p>production.js</p>
  
  <pre><code>var config = {   
    production: {  
      session: {    
        key: 'the.express.session.id',    
        secret: 'something.super.secret'    
      },    
      database: 'mongodb://localhost:27018/test',    
      twitter: {    
        consumerKey: 'consumer Key',    
        consumerSecret: 'consumer Secret',    
        callbackURL: 'http://yoururl.com/auth/twitter/callback'    
      }    
    },    
  }
  </code></pre>
  
  <p>development.js</p>
  
  <pre><code>var config = {    
    development: {    
      session: {    
        key: 'the.express.session.id',    
        secret: 'something.super.secret'    
      },    
      database: 'mongodb://localhost:27018/testdata',    
      twitter: {    
        consumerKey: 'consumer Key',    
        consumerSecret: 'consumer Secret',    
        callbackURL: 'http://yoururl.com/auth/twitter/callback'    
      }    
    },    
  }
  </code></pre>
  
  <p>I have stored these files under environment folder now i want to call these two files in server.js </p>
  
  <p>server.js</p>
  
  <pre><code>var config = require('./environment');    
  console.log(config);    
  
  mongoose.connect(config.database);    
  mongoose.connection.on('error', function (err) {    
    console.error('MongoDB connection error: ' + err);    
    process.exit(-1);    
  });
  </code></pre>
  
  <p>How can i call those file in server.js .if i run <code>set NODE_ENV=production</code> in command prompt these should run <code>production</code> database and if i run <code>set NODE_ENV=development</code> in command prompt <code>development</code> database should run .help me out </p>