Skip to content

Commit 26f3023

Browse files
committed
Wrap FAQ in details
1 parent 8b8493f commit 26f3023

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

README.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ Override any environment variables that have already been set.
533533

534534
## FAQ
535535

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>
537538

538539
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).
539540

@@ -544,23 +545,29 @@ require('dotenv').config({ debug: true })
544545
```
545546

546547
You will receive a helpful error outputted to your console.
548+
</details>
547549

548-
### Should I commit my `.env` file?
550+
<details>
551+
<summary>Should I commit my `.env` file?</summary>
549552

550553
No. We **strongly** recommend against committing your `.env` file to version
551554
control. It should only include environment-specific values such as database
552555
passwords or API keys. Your production database should have a different
553556
password than your development database.
557+
</details>
554558

555-
### Should I have multiple `.env` files?
559+
<details>
560+
<summary>Should I have multiple `.env` files?</summary>
556561

557562
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.
558563

559564
> 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.
560565
>
561566
> [The Twelve-Factor App](http://12factor.net/config)
567+
</details>
562568
563-
### What rules does the parsing engine follow?
569+
<details>
570+
<summary>What rules does the parsing engine follow?</summary>
564571

565572
The parsing engine currently supports the following rules:
566573

@@ -581,8 +588,10 @@ line'}
581588
```
582589

583590
- backticks are supported (`` BACKTICK_KEY=`This has 'single' and "double" quotes inside of it.` ``)
591+
</details>
584592

585-
### What happens to environment variables that were already set?
593+
<details>
594+
<summary>What happens to environment variables that were already set?</summary>
586595

587596
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.
588597

@@ -591,16 +600,20 @@ If instead, you want to override `process.env` use the `override` option.
591600
```javascript
592601
require('dotenv').config({ override: true })
593602
```
603+
</details>
594604

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>
596607

597608
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.
598609

599610
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.
600611

601612
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>
602614

603-
### Can I customize/write plugins for dotenv?
615+
<details>
616+
<summary>Can I customize/write plugins for dotenv?</summary>
604617

605618
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:
606619

@@ -610,8 +623,10 @@ const variableExpansion = require('dotenv-expand')
610623
const myEnv = dotenv.config()
611624
variableExpansion(myEnv)
612625
```
626+
</details>
613627

614-
### How do I use dotenv with `import`?
628+
<details>
629+
<summary>How do I use dotenv with `import`?</summary>
615630

616631
Simply..
617632

@@ -666,8 +681,10 @@ There are two alternatives to this approach:
666681

667682
1. Preload with dotenvx: `dotenvx run -- node index.js` (_Note: you do not need to `import` dotenv with this approach_)
668683
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>
669685

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>
671688

672689
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:
673690

@@ -704,25 +721,33 @@ module.exports = {
704721
```
705722

706723
Alternatively, just use [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack) which does this and more behind the scenes for you.
724+
</details>
707725

708-
### What about variable expansion?
726+
<details>
727+
<summary>What about variable expansion?</summary>
709728

710729
Try [dotenv-expand](https://github.com/motdotla/dotenv-expand)
730+
</details>
711731

712-
### What about syncing and securing .env files?
732+
<details>
733+
<summary>What about syncing and securing .env files?</summary>
713734

714735
Use [dotenvx](https://github.com/dotenvx/dotenvx) to unlock syncing encrypted .env files over git.
736+
</details>
715737

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>
717740

718741
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.
719742

720743
```
721744
brew install dotenvx/brew/dotenvx
722745
dotenvx precommit --install
723746
```
747+
</details>
724748

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>
726751

727752
Use the [docker prebuild hook](https://dotenvx.com/docs/features/prebuild).
728753

@@ -734,6 +759,7 @@ RUN curl -fsS https://dotenvx.sh/ | sh
734759
RUN dotenvx prebuild
735760
CMD ["dotenvx", "run", "--", "node", "index.js"]
736761
```
762+
</details>
737763

738764
## Contributing Guide
739765

0 commit comments

Comments
 (0)