@@ -14,7 +14,9 @@ Install it.
1414npm install dotenv --save
1515```
1616
17- <details ><summary >with yarn, bun, or pnpm (expand)</summary ><br >
17+ <details ><summary >learn more</summary ><br >
18+
19+ You can use any npm-compatible package manager like yarn, bun, or pnpm.
1820
1921``` sh
2022yarn add dotenv
@@ -26,16 +28,25 @@ pnpm add dotenv
2628
2729</details >
2830
31+   ;
32+
2933Create a ` .env ` file in the root of your project:
3034
31- ``` dosini
35+ ``` ini
36+ # .env
3237S3_BUCKET =" YOURS3BUCKET"
3338SECRET_KEY =" YOURSECRETKEYGOESHERE"
3439```
3540
36- <details ><summary >for monorepos (expand)</summary ><br >
41+ <details ><summary >learn more</summary ><br >
42+
43+ For monorepos with a structure like ` apps/backend/app.js ` , put it in the root of the folder where your ` app.js ` process runs.
3744
38- If using a monorepo structure like ` apps/backend/app.js ` , put it in the root of the folder where your ` app.js ` process runs.
45+ ``` ini
46+ # app/backend/.env
47+ S3_BUCKET =" YOURS3BUCKET"
48+ SECRET_KEY =" YOURSECRETKEYGOESHERE"
49+ ```
3950
4051  ;
4152
@@ -48,28 +59,29 @@ require('dotenv').config()
4859console .log (process .env ) // remove this after you've confirmed it is working
4960```
5061
51- .. [ or using ES6?] ( #how-do-i-use-dotenv-with-import )
62+ <details ><summary >learn more</summary ><br >
63+
64+ If you are [ using ES6] ( #how-do-i-use-dotenv-with-import ) :
5265
5366``` javascript
5467import ' dotenv/config'
5568```
5669
57- ES6 import if you need to set config options:
70+ or using ES6 import with config options:
5871
5972``` javascript
6073import dotenv from ' dotenv'
6174
6275dotenv .config ({ path: ' /custom/path/to/.env' })
6376```
6477
78+ </details >
79+
6580That's it. ` process.env ` now has the keys and values you defined in your ` .env ` file:
6681
6782``` javascript
68- require (' dotenv' ).config ()
69- // or import 'dotenv/config' if you're using ES6
70-
83+ require (' dotenv' ).config () // or import 'dotenv/config' if you're using ES6
7184...
72-
7385s3 .getBucketCors ({Bucket: process .env .S3_BUCKET }, function (err , data ) {})
7486```
7587
@@ -89,7 +101,7 @@ s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
89101
90102Create a ` .env ` file in the root of your project (if using a monorepo structure like ` apps/backend/app.js ` , put it in the root of the folder where your ` app.js ` process runs):
91103
92- ``` dosini
104+ ``` ini
93105S3_BUCKET =" YOURS3BUCKET"
94106SECRET_KEY =" YOURSECRETKEYGOESHERE"
95107```
@@ -130,7 +142,7 @@ s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
130142
131143If you need multiline variables, for example private keys, those are now supported (` >= v15.0.0 ` ) with line breaks:
132144
133- ``` dosini
145+ ``` ini
134146PRIVATE_KEY =" -----BEGIN RSA PRIVATE KEY-----
135147...
136148Kh9NV...
@@ -140,15 +152,15 @@ Kh9NV...
140152
141153Alternatively, you can double quote strings and use the ` \n ` character:
142154
143- ``` dosini
155+ ``` ini
144156PRIVATE_KEY =" -----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END RSA PRIVATE KEY-----\n"
145157```
146158
147159### Comments
148160
149161Comments may be added to your file on their own line or inline:
150162
151- ``` dosini
163+ ``` ini
152164# This is a comment
153165SECRET_KEY =YOURSECRETKEYGOESHERE # comment
154166SECRET_HASH =" something-with-a-#-hash"
0 commit comments