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
+66Lines changed: 66 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,8 @@ import dotenv from 'dotenv'
75
75
dotenv.config({ path:'/custom/path/to/.env' })
76
76
```
77
77
78
+
Need to pass options like `quiet: true`? See the [FAQ below](#how-do-i-specify-config-options-with-es6-import) for common patterns. 😊
79
+
78
80
</details>
79
81
<details><summary>bun</summary><br>
80
82
@@ -421,6 +423,70 @@ There are two alternatives to this approach:
421
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)
422
424
</details>
423
425
426
+
<details><summary>How do I specify config options with ES6 import?</summary><br/>
427
+
428
+
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:
429
+
430
+
**Option 1: Import and call `config()` yourself (Recommended)**
431
+
432
+
```javascript
433
+
// index.mjs
434
+
importdotenvfrom'dotenv'
435
+
436
+
dotenv.config({
437
+
quiet:true,
438
+
path:'/custom/path/to/.env',
439
+
debug:true
440
+
})
441
+
442
+
// Now import everything else
443
+
importexpressfrom'express'
444
+
```
445
+
446
+
⚠️ **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 |
486
+
|`quiet`| boolean | Suppress all console output |
487
+
488
+
</details>
489
+
424
490
<details><summary>Can I customize/write plugins for dotenv?</summary><br/>
425
491
426
492
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:
0 commit comments