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
+53-66Lines changed: 53 additions & 66 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,8 +77,6 @@ import dotenv from 'dotenv'
77
77
dotenv.config({ path:'/custom/path/to/.env' })
78
78
```
79
79
80
-
Need to pass options like `quiet: true`? See the [FAQ below](#how-do-i-specify-config-options-with-es6-import) for common patterns. 😊
81
-
82
80
</details>
83
81
<details><summary>bun</summary><br>
84
82
@@ -425,70 +423,6 @@ There are two alternatives to this approach:
425
423
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)
426
424
</details>
427
425
428
-
<details><summary>How do I specify config options with ES6 import?</summary><br/>
429
-
430
-
This trips up a lot of folks (myself included the first time 😅). When using `import 'dotenv/config'`, you can't pass options directly. Here are a few practical ways to handle it:
431
-
432
-
**Option 1: Import and call `config()` yourself (Recommended)**
433
-
434
-
```javascript
435
-
// index.mjs
436
-
importdotenvfrom'dotenv'
437
-
438
-
dotenv.config({
439
-
quiet:true,
440
-
path:'/custom/path/to/.env',
441
-
debug:true
442
-
})
443
-
444
-
// Now import everything else
445
-
importexpressfrom'express'
446
-
```
447
-
448
-
⚠️ **Heads up:** Because ES6 imports are hoisted, put the `dotenv` import and `config()` call at the very top, before any other imports that rely on `process.env`.
|`override`| boolean | Override existing env vars |
488
-
|`quiet`| boolean | Suppress all console output |
489
-
490
-
</details>
491
-
492
426
<details><summary>Can I customize/write plugins for dotenv?</summary><br/>
493
427
494
428
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:
@@ -538,6 +472,59 @@ npm i -g @dotenvx/dotenvx
538
472
dotenvx precommit --install
539
473
```
540
474
475
+
</details>
476
+
477
+
<details><summary>How do I specify config options with ES6 import?</summary><br/>
478
+
479
+
When using `import 'dotenv/config'`, you can't pass options directly. Here are a few ways to handle it.
480
+
481
+
**Option 1: Import and call `config()` yourself (Recommended)**
482
+
483
+
```javascript
484
+
// index.mjs
485
+
importdotenvfrom'dotenv'
486
+
487
+
dotenv.config({
488
+
path:'/custom/path/to/.env',
489
+
debug:true
490
+
})
491
+
492
+
// Now import everything else
493
+
importexpressfrom'express'
494
+
```
495
+
496
+
Because ES6 imports are hoisted, put the `dotenv` import and `config()` call at the very top, before any other imports that rely on `process.env`.
0 commit comments