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
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
-
importdotenvfrom'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:
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.
147
106
148
-
### Parsing
107
+
</details>
108
+
109
+
110
+
<details><summary>Parsing</summary><br>
149
111
150
112
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.
151
113
@@ -156,7 +118,8 @@ const config = dotenv.parse(buf) // will return an object
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.
Use [dotenvx](https://github.com/dotenvx/dotenvx) to generate `.env.ci`, `.env.production` files, and more.
235
202
236
-
### Deploying
203
+
</details>
204
+
205
+
<details><summary>Deploying</summary><br>
237
206
238
207
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.
239
208
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
+
importdotenvfrom'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:
0 commit comments