Skip to content

Commit 630fd75

Browse files
committed
update README
1 parent 3e00c83 commit 630fd75

File tree

1 file changed

+65
-55
lines changed

1 file changed

+65
-55
lines changed

README.md

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
>
77
> [2 minute tutorial 📺](https://www.youtube.com/watch?v=YtkZR0NFd1g)
88
9-
### Quickstart
9+
 
10+
11+
### Usage
1012

1113
Install it.
1214

@@ -69,53 +71,9 @@ s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
6971
* [Deploying](#deploying)
7072
* [Agents (AS2) 🆕](#agents-as2)
7173

72-
## Usage
73-
74-
<a href="https://www.youtube.com/watch?v=YtkZR0NFd1g">
75-
<img src="https://img.youtube.com/vi/YtkZR0NFd1g/hqdefault.jpg" alt="how to use dotenv video tutorial" align="right" width="330" />
76-
<img src="https://simpleicons.vercel.app/youtube/ff0000" alt="youtube/@dotenvorg" align="right" width="24" />
77-
</a>
78-
79-
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):
80-
81-
```ini
82-
S3_BUCKET="YOURS3BUCKET"
83-
SECRET_KEY="YOURSECRETKEYGOESHERE"
84-
```
85-
86-
As early as possible in your application, import and configure dotenv:
87-
88-
```javascript
89-
require('dotenv').config()
90-
console.log(process.env) // remove this after you've confirmed it is working
91-
```
92-
93-
.. [or using ES6?](#how-do-i-use-dotenv-with-import)
94-
95-
```javascript
96-
import 'dotenv/config'
97-
```
98-
99-
ES6 import if you need to set config options:
100-
101-
```javascript
102-
import dotenv from 'dotenv'
103-
104-
dotenv.config({ path: '/custom/path/to/.env' })
105-
```
106-
107-
That's it. `process.env` now has the keys and values you defined in your `.env` file:
108-
109-
```javascript
110-
require('dotenv').config()
111-
// or import 'dotenv/config' if you're using ES6
112-
113-
...
114-
115-
s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
116-
```
74+
## Advanced
11775

118-
### Multiline values
76+
<details><summary>Multiline Values</summary><br>
11977

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

@@ -133,7 +91,8 @@ Alternatively, you can double quote strings and use the `\n` character:
13391
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END RSA PRIVATE KEY-----\n"
13492
```
13593

136-
### Comments
94+
</details>
95+
<details><summary>Comments</summary><br>
13796

13897
Comments may be added to your file on their own line or inline:
13998

@@ -145,7 +104,10 @@ SECRET_HASH="something-with-a-#-hash"
145104

146105
Comments begin where a `#` exists, so if your value contains a `#` please wrap it in quotes. This is a breaking change from `>= v15.0.0` and on.
147106

148-
### Parsing
107+
</details>
108+
109+
110+
<details><summary>Parsing</summary><br>
149111

150112
The engine which parses the contents of your file containing environment variables is available to use. It accepts a String or Buffer and will return an Object with the parsed keys and values.
151113

@@ -156,7 +118,8 @@ const config = dotenv.parse(buf) // will return an object
156118
console.log(typeof config, config) // object { BASIC : 'basic' }
157119
```
158120

159-
### Preload
121+
</details>
122+
<details><summary>Preload</summary><br>
160123

161124
> Note: Consider using [`dotenvx`](https://github.com/dotenvx/dotenvx) instead of preloading. I am now doing (and recommending) so.
162125
>
@@ -184,7 +147,8 @@ $ DOTENV_CONFIG_<OPTION>=value node -r dotenv/config your_script.js
184147
$ DOTENV_CONFIG_ENCODING=latin1 DOTENV_CONFIG_DEBUG=true node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env
185148
```
186149

187-
### Variable Expansion
150+
</details>
151+
<details><summary>Variable Expansion</summary><br>
188152

189153
Use [dotenvx](https://github.com/dotenvx/dotenvx) to use variable expansion.
190154

@@ -205,7 +169,8 @@ $ dotenvx run --debug -- node index.js
205169
DATABASE_URL postgres://username@localhost/my_database
206170
```
207171

208-
### Command Substitution
172+
</details>
173+
<details><summary>Command Substitution</summary><br>
209174

210175
Use [dotenvx](https://github.com/dotenvx/dotenvx) to use command substitution.
211176

@@ -225,18 +190,63 @@ $ dotenvx run --debug -- node index.js
225190
DATABASE_URL postgres://yourusername@localhost/my_database
226191
```
227192

228-
### Syncing
193+
</details>
194+
<details><summary>Syncing</summary><br>
229195

230196
You need to keep `.env` files in sync between machines, environments, or team members? Use [dotenvx](https://github.com/dotenvx/dotenvx) to encrypt your `.env` files and safely include them in source control. This still subscribes to the twelve-factor app rules by generating a decryption key separate from code.
231197

232-
### Multiple Environments
198+
</details>
199+
<details><summary>Multiple Environments</summary><br>
233200

234201
Use [dotenvx](https://github.com/dotenvx/dotenvx) to generate `.env.ci`, `.env.production` files, and more.
235202

236-
### Deploying
203+
</details>
204+
205+
<details><summary>Deploying</summary><br>
237206

238207
You need to deploy your secrets in a cloud-agnostic manner? Use [dotenvx](https://github.com/dotenvx/dotenvx) to generate a private decryption key that is set on your production server.
239208

209+
</details>
210+
211+
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):
212+
213+
```ini
214+
S3_BUCKET="YOURS3BUCKET"
215+
SECRET_KEY="YOURSECRETKEYGOESHERE"
216+
```
217+
218+
As early as possible in your application, import and configure dotenv:
219+
220+
```javascript
221+
require('dotenv').config()
222+
console.log(process.env) // remove this after you've confirmed it is working
223+
```
224+
225+
.. [or using ES6?](#how-do-i-use-dotenv-with-import)
226+
227+
```javascript
228+
import 'dotenv/config'
229+
```
230+
231+
ES6 import if you need to set config options:
232+
233+
```javascript
234+
import dotenv from 'dotenv'
235+
236+
dotenv.config({ path: '/custom/path/to/.env' })
237+
```
238+
239+
That's it. `process.env` now has the keys and values you defined in your `.env` file:
240+
241+
```javascript
242+
require('dotenv').config()
243+
// or import 'dotenv/config' if you're using ES6
244+
245+
...
246+
247+
s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
248+
```
249+
240250
&nbsp;
241251

242252
## Multiple Environments

0 commit comments

Comments
 (0)