Skip to content

Commit 04ba055

Browse files
committed
update README
1 parent 2077590 commit 04ba055

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Install it.
1414
npm 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
2022
yarn add dotenv
@@ -26,16 +28,25 @@ pnpm add dotenv
2628

2729
</details>
2830

31+
&nbsp;
32+
2933
Create a `.env` file in the root of your project:
3034

31-
```dosini
35+
```ini
36+
# .env
3237
S3_BUCKET="YOURS3BUCKET"
3338
SECRET_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
&nbsp;
4152

@@ -48,28 +59,29 @@ require('dotenv').config()
4859
console.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
5467
import '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
6073
import dotenv from 'dotenv'
6174

6275
dotenv.config({ path: '/custom/path/to/.env' })
6376
```
6477

78+
</details>
79+
6580
That'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-
7385
s3.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

90102
Create 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
93105
S3_BUCKET="YOURS3BUCKET"
94106
SECRET_KEY="YOURSECRETKEYGOESHERE"
95107
```
@@ -130,7 +142,7 @@ s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
130142

131143
If you need multiline variables, for example private keys, those are now supported (`>= v15.0.0`) with line breaks:
132144

133-
```dosini
145+
```ini
134146
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
135147
...
136148
Kh9NV...
@@ -140,15 +152,15 @@ Kh9NV...
140152

141153
Alternatively, you can double quote strings and use the `\n` character:
142154

143-
```dosini
155+
```ini
144156
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END RSA PRIVATE KEY-----\n"
145157
```
146158

147159
### Comments
148160

149161
Comments may be added to your file on their own line or inline:
150162

151-
```dosini
163+
```ini
152164
# This is a comment
153165
SECRET_KEY=YOURSECRETKEYGOESHERE # comment
154166
SECRET_HASH="something-with-a-#-hash"

0 commit comments

Comments
 (0)