You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<summary>Should I commit my `.env` file?</summary>
540
+
</details>
541
+
<details><summary>Should I commit my `.env` file?</summary><br/>
544
542
545
543
No. We **strongly** recommend against committing your `.env` file to version
544
+
546
545
control. It should only include environment-specific values such as database
547
546
passwords or API keys. Your production database should have a different
548
547
password than your development database.
549
-
</details>
550
548
551
-
<details>
552
-
<summary>How do I use dotenv with `import`?</summary>
549
+
</details>
550
+
<details><summary>How do I use dotenv with `import`?</summary><br/>
553
551
554
552
Simply..
555
553
@@ -606,18 +604,15 @@ There are two alternatives to this approach:
606
604
2. Create a separate file that will execute `config` first as outlined in [this comment on #133](https://github.com/motdotla/dotenv/issues/133#issuecomment-255298822)
607
605
</details>
608
606
609
-
<details>
610
-
<summary>Should I have multiple `.env` files?</summary>
607
+
<details><summary>Should I have multiple `.env` files?</summary><br/>
611
608
612
609
We recommend creating one `.env` file per environment. Use `.env` for local/development, `.env.production` for production and so on. This still follows the twelve factor principles as each is attributed individually to its own environment. Avoid custom set ups that work in inheritance somehow (`.env.production` inherits values form `.env` for example). It is better to duplicate values if necessary across each `.env.environment` file.
613
610
614
611
> In a twelve-factor app, env vars are granular controls, each fully orthogonal to other env vars. They are never grouped together as “environments”, but instead are independently managed for each deploy. This is a model that scales up smoothly as the app naturally expands into more deploys over its lifetime.
<summary>Can I customize/write plugins for dotenv?</summary>
615
+
<details><summary>Can I customize/write plugins for dotenv?</summary><br/>
621
616
622
617
Yes! `dotenv.config()` returns an object representing the parsed `.env` file. This gives you everything you need to continue setting values on `process.env`. For example:
623
618
@@ -628,9 +623,7 @@ const myEnv = dotenv.config()
628
623
variableExpansion(myEnv)
629
624
```
630
625
</details>
631
-
632
-
<details>
633
-
<summary>What rules does the parsing engine follow?</summary>
626
+
<details><summary>What rules does the parsing engine follow?</summary><br/>
634
627
635
628
The parsing engine currently supports the following rules:
636
629
@@ -651,27 +644,24 @@ line'}
651
644
```
652
645
653
646
- backticks are supported (`` BACKTICK_KEY=`This has 'single' and "double" quotes inside of it.` ``)
654
-
</details>
655
647
656
-
<details>
657
-
<summary>What about syncing and securing .env files?</summary>
648
+
</details>
649
+
<details><summary>What about syncing and securing .env files?</summary><br/>
658
650
659
651
Use [dotenvx](https://github.com/dotenvx/dotenvx) to unlock syncing encrypted .env files over git.
660
-
</details>
661
652
662
-
<details>
663
-
<summary>What if I accidentally commit my `.env` file to code?</summary>
653
+
</details>
654
+
<details><summary>What if I accidentally commit my `.env` file to code?</summary><br/>
664
655
665
656
Remove it, [remove git history](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository) and then install the [git pre-commit hook](https://github.com/dotenvx/dotenvx#pre-commit) to prevent this from ever happening again.
666
657
667
658
```
668
659
brew install dotenvx/brew/dotenvx
669
660
dotenvx precommit --install
670
661
```
671
-
</details>
672
662
673
-
<details>
674
-
<summary>What happens to environment variables that were already set?</summary>
663
+
</details>
664
+
<details><summary>What happens to environment variables that were already set?</summary><br/>
675
665
676
666
By default, we will never modify any environment variables that have already been set. In particular, if there is a variable in your `.env` file which collides with one that already exists in your environment, then that variable will be skipped.
677
667
@@ -680,10 +670,9 @@ If instead, you want to override `process.env` use the `override` option.
680
670
```javascript
681
671
require('dotenv').config({ override:true })
682
672
```
683
-
</details>
684
673
685
-
<details>
686
-
<summary>How can I prevent committing my `.env` file to a Docker build?</summary>
674
+
</details>
675
+
<details><summary>How can I prevent committing my `.env` file to a Docker build?</summary><br/>
687
676
688
677
Use the [docker prebuild hook](https://dotenvx.com/docs/features/prebuild).
689
678
@@ -695,20 +684,18 @@ RUN curl -fsS https://dotenvx.sh/ | sh
695
684
RUN dotenvx prebuild
696
685
CMD ["dotenvx", "run", "--", "node", "index.js"]
697
686
```
698
-
</details>
699
687
700
-
<details>
701
-
<summary>How come my environment variables are not showing up for React?</summary>
688
+
</details>
689
+
<details><summary>How come my environment variables are not showing up for React?</summary><br/>
702
690
703
691
Your React code is run in Webpack, where the `fs` module or even the `process` global itself are not accessible out-of-the-box. `process.env` can only be injected through Webpack configuration.
704
692
705
693
If you are using [`react-scripts`](https://www.npmjs.com/package/react-scripts), which is distributed through [`create-react-app`](https://create-react-app.dev/), it has dotenv built in but with a quirk. Preface your environment variables with `REACT_APP_`. See [this stack overflow](https://stackoverflow.com/questions/42182577/is-it-possible-to-use-dotenv-in-a-react-project) for more details.
706
694
707
695
If you are using other frameworks (e.g. Next.js, Gatsby...), you need to consult their documentation for how to inject environment variables into the client.
708
-
</details>
709
696
710
-
<details>
711
-
<summary>Why is the `.env` file not loading my environment variables successfully?</summary>
697
+
</details>
698
+
<details><summary>Why is the `.env` file not loading my environment variables successfully?</summary><br/>
712
699
713
700
Most likely your `.env` file is not in the correct place. [See this stack overflow](https://stackoverflow.com/questions/42335016/dotenv-file-is-not-loading-environment-variables).
0 commit comments