title: how to setup dotenv in development and production?
body: <p>In my Express JS API server, I tried to use dotenv with a <code>.env</code> file for my environment setup.  </p>
  
  <p>I prefer to use the <code>.env</code> file for both development and production environment.</p>
  
  <p>I am using nodemon for my development, currently if I include <code>-r dotenv/config</code> in package.json > start script:</p>
  
  <pre><code>    "scripts": {
          "start": "nodemon --exec babel-node -r dotenv/config index.js"
      }
  </code></pre>
  
  <p>the variables setup correctly in <code>process.env</code> everwhere in the app</p>
  
  <p>However, if I use script to config dotenv in <code>index.js</code> like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>import dotenv from 'dotenv'
  // Environment variables
  dotenv.config()
  </code></pre>
  
  <p><strong>seems <code>process.env</code> only configed in index.js page, I cannot get <code>process.env</code> variables in my middleware logic?</strong><br>
  I have put <code>dotenv.config()</code> executed at the very beginning before middleware executed</p>
  
  <p>My questions are:<br>
  1. is my logic using <code>dotenv.config()</code> not a correct setup? why my middleware cannot get the same variables?<br>
  2. How to setup <code>process.env</code> variables read from <code>.env</code> file for both development and production? (I may use webpack to package my production version)</p>
  
  <p>Thanks for any help.</p>