title: Running an .env file and access them from Node
body: <p>This feels a bit embarrassing since I've been a Linux user for 10+ years. However, I've ran into a problem which I can't understand.</p>
  
  <p>Lets assume I want to expose an environment variable, <code>SECRET</code>, that I can access from node with 
  <code>process.env.SECRET</code></p>
  
  <p>I would just write this is the same terminal that I start the app with</p>
  
  <pre><code># Linux bash
  $ export SECRET=Ultr4Secr3t
  $ echo $SECRET
  $ &gt; Ultr4Secr3t
  </code></pre>
  
  <p>Then run node app <code>nodejs app.js</code></p>
  
  <pre class="lang-js prettyprint-override"><code>// app.js
  console.log(process.env.SECRET)
  &gt; Ultr4Secr3t
  </code></pre>
  
  <p>Everything is fine!</p>
  
  <p>But I would really like to have an .env file in the repo instead.</p>
  
  <p>Example .env file</p>
  
  <pre><code>SECRET=Ultr4Secr3t
  </code></pre>
  
  <pre><code># Linux bash
  $ . .env # On Mac we had to do ". ./.env"
  $ echo $SECRET
  $ Ultr4Secr3t
  </code></pre>
  
  <p>Now the weird thing happens when I run the app</p>
  
  <p>Then run node app <code>nodejs app.js</code></p>
  
  <pre class="lang-js prettyprint-override"><code>// app.js
  console.log(process.env.SECRET)
  &gt; undefined
  </code></pre>
  
  <p>Why is it <code>undefined</code>? I'd rather not have to use the <code>dotenv</code> package.</p>