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
Copy file name to clipboardExpand all lines: README.md
+39-13Lines changed: 39 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -533,7 +533,8 @@ Override any environment variables that have already been set.
533
533
534
534
## FAQ
535
535
536
-
### Why is the `.env` file not loading my environment variables successfully?
536
+
<details>
537
+
<summary>Why is the `.env` file not loading my environment variables successfully?</summary>
537
538
538
539
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).
You will receive a helpful error outputted to your console.
548
+
</details>
547
549
548
-
### Should I commit my `.env` file?
550
+
<details>
551
+
<summary>Should I commit my `.env` file?</summary>
549
552
550
553
No. We **strongly** recommend against committing your `.env` file to version
551
554
control. It should only include environment-specific values such as database
552
555
passwords or API keys. Your production database should have a different
553
556
password than your development database.
557
+
</details>
554
558
555
-
### Should I have multiple `.env` files?
559
+
<details>
560
+
<summary>Should I have multiple `.env` files?</summary>
556
561
557
562
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.
558
563
559
564
> 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>What rules does the parsing engine follow?</summary>
564
571
565
572
The parsing engine currently supports the following rules:
566
573
@@ -581,8 +588,10 @@ line'}
581
588
```
582
589
583
590
- backticks are supported (`` BACKTICK_KEY=`This has 'single' and "double" quotes inside of it.` ``)
591
+
</details>
584
592
585
-
### What happens to environment variables that were already set?
593
+
<details>
594
+
<summary>What happens to environment variables that were already set?</summary>
586
595
587
596
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.
588
597
@@ -591,16 +600,20 @@ If instead, you want to override `process.env` use the `override` option.
591
600
```javascript
592
601
require('dotenv').config({ override:true })
593
602
```
603
+
</details>
594
604
595
-
### How come my environment variables are not showing up for React?
605
+
<details>
606
+
<summary>How come my environment variables are not showing up for React?</summary>
596
607
597
608
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.
598
609
599
610
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.
600
611
601
612
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.
613
+
</details>
602
614
603
-
### Can I customize/write plugins for dotenv?
615
+
<details>
616
+
<summary>Can I customize/write plugins for dotenv?</summary>
604
617
605
618
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:
<summary>How do I use dotenv with `import`?</summary>
615
630
616
631
Simply..
617
632
@@ -666,8 +681,10 @@ There are two alternatives to this approach:
666
681
667
682
1. Preload with dotenvx: `dotenvx run -- node index.js` (_Note: you do not need to `import` dotenv with this approach_)
668
683
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)
684
+
</details>
669
685
670
-
### Why am I getting the error `Module not found: Error: Can't resolve 'crypto|os|path'`?
686
+
<details>
687
+
<summary>Why am I getting the error `Module not found: Error: Can't resolve 'crypto|os|path'`?</summary>
671
688
672
689
You are using dotenv on the front-end and have not included a polyfill. Webpack < 5 used to include these for you. Do the following:
673
690
@@ -704,25 +721,33 @@ module.exports = {
704
721
```
705
722
706
723
Alternatively, just use [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack) which does this and more behind the scenes for you.
<summary>What about syncing and securing .env files?</summary>
713
734
714
735
Use [dotenvx](https://github.com/dotenvx/dotenvx) to unlock syncing encrypted .env files over git.
736
+
</details>
715
737
716
-
### What if I accidentally commit my `.env` file to code?
738
+
<details>
739
+
<summary>What if I accidentally commit my `.env` file to code?</summary>
717
740
718
741
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.
719
742
720
743
```
721
744
brew install dotenvx/brew/dotenvx
722
745
dotenvx precommit --install
723
746
```
747
+
</details>
724
748
725
-
### How can I prevent committing my `.env` file to a Docker build?
749
+
<details>
750
+
<summary>How can I prevent committing my `.env` file to a Docker build?</summary>
726
751
727
752
Use the [docker prebuild hook](https://dotenvx.com/docs/features/prebuild).
728
753
@@ -734,6 +759,7 @@ RUN curl -fsS https://dotenvx.sh/ | sh
0 commit comments