<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ujwala p</title>
    <description>The latest articles on DEV Community by ujwala p (@ujwala_dev).</description>
    <link>https://dev.to/ujwala_dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4062843%2F05171528-7adc-4af7-b462-85fe45107502.png</url>
      <title>DEV Community: ujwala p</title>
      <link>https://dev.to/ujwala_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ujwala_dev"/>
    <language>en</language>
    <item>
      <title>.env vs .env.example: What's the Difference and Why You Need Both</title>
      <dc:creator>ujwala p</dc:creator>
      <pubDate>Tue, 04 Aug 2026 16:40:21 +0000</pubDate>
      <link>https://dev.to/ujwala_dev/-env-vs-envexample-whats-the-difference-4gh7</link>
      <guid>https://dev.to/ujwala_dev/-env-vs-envexample-whats-the-difference-4gh7</guid>
      <description>&lt;p&gt;If you've cloned an open-source project from GitHub, you've probably seen these two files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.env
.env.example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, they look similar, but they serve completely different purposes.&lt;/p&gt;

&lt;p&gt;Let's understand the difference.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is a &lt;code&gt;.env&lt;/code&gt; file?
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;.env&lt;/code&gt; file contains the &lt;strong&gt;actual environment variables&lt;/strong&gt; that your application uses while running.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL=postgres://user:password@localhost:5432/mydb
JWT_SECRET=mySuperSecretKey
API_KEY=abc123xyz
PORT=3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These values are &lt;strong&gt;real secrets&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Your application reads them at runtime using libraries like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;dotenv&lt;/code&gt; (Node.js)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;python-dotenv&lt;/code&gt; (Python)&lt;/li&gt;
&lt;li&gt;Framework-specific environment loaders&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why shouldn't you commit &lt;code&gt;.env&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;Because it contains sensitive information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Database credentials&lt;/li&gt;
&lt;li&gt;API keys&lt;/li&gt;
&lt;li&gt;JWT secrets&lt;/li&gt;
&lt;li&gt;OAuth client secrets&lt;/li&gt;
&lt;li&gt;Cloud service credentials&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If someone gets access to these values, they may gain unauthorized access to your services.&lt;/p&gt;

&lt;p&gt;That's why &lt;code&gt;.env&lt;/code&gt; is usually added to &lt;code&gt;.gitignore&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  What is a &lt;code&gt;.env.example&lt;/code&gt; file?
&lt;/h2&gt;

&lt;p&gt;A &lt;code&gt;.env.example&lt;/code&gt; file is simply a &lt;strong&gt;template&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It shows other developers which environment variables are required, &lt;strong&gt;without exposing the actual values&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL=
JWT_SECRET=
API_KEY=
PORT=3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or with placeholder values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL=your_database_url
JWT_SECRET=your_jwt_secret
API_KEY=your_api_key
PORT=3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that there are &lt;strong&gt;no real secrets&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why do we need &lt;code&gt;.env.example&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Imagine a new developer clones your project.&lt;/p&gt;

&lt;p&gt;Without documentation, they have no idea which environment variables are required.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;.env.example&lt;/code&gt; solves this problem.&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What environment variables do I need?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;They can simply run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; .env.example .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then update the values.&lt;/p&gt;




&lt;h2&gt;
  
  
  Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;code&gt;.env&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;.env.example&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Contains real values&lt;/td&gt;
&lt;td&gt;Contains placeholder values&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Used by the application&lt;/td&gt;
&lt;td&gt;Used by developers as a template&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Should not be committed&lt;/td&gt;
&lt;td&gt;Safe to commit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Usually listed in &lt;code&gt;.gitignore&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Usually tracked in Git&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Contains secrets&lt;/td&gt;
&lt;td&gt;Contains no secrets&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Typical Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project/
│
├── .env
├── .env.example
├── .gitignore
├── package.json
└── src/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;.gitignore&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Workflow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repository.&lt;/li&gt;
&lt;li&gt;Copy the example file.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; .env.example .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Fill in the actual credentials.&lt;/li&gt;
&lt;li&gt;Start the application.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every developer now has their own private &lt;code&gt;.env&lt;/code&gt; file.&lt;/p&gt;




&lt;h2&gt;
  
  
  Best Practices
&lt;/h2&gt;

&lt;p&gt;✅ Commit &lt;code&gt;.env.example&lt;/code&gt; to your repository.&lt;/p&gt;

&lt;p&gt;✅ Add &lt;code&gt;.env&lt;/code&gt; to &lt;code&gt;.gitignore&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;✅ Never store production secrets in Git.&lt;/p&gt;

&lt;p&gt;✅ Keep &lt;code&gt;.env.example&lt;/code&gt; updated whenever a new environment variable is added.&lt;/p&gt;

&lt;p&gt;✅ Use meaningful placeholder values instead of real credentials.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;.env&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL=postgres://admin:password123@localhost:5432/shop
JWT_SECRET=s8K@91aP!dX2
API_KEY=sk_live_xxxxxxxxxxxxxxxxx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;.env.example&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL=your_database_url
JWT_SECRET=your_jwt_secret
API_KEY=your_api_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how the structure is identical, but the sensitive values are removed.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Think of these files like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.env&lt;/code&gt;&lt;/strong&gt; = Your personal wallet (contains your real money and should stay private).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;.env.example&lt;/code&gt;&lt;/strong&gt; = A checklist showing what belongs in the wallet (safe to share with everyone).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following this practice makes your projects more secure, easier to onboard new developers, and more professional for open-source collaboration.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>javascript</category>
      <category>security</category>
      <category>dotenv</category>
    </item>
  </channel>
</rss>
