|
2 | 2 |
|
3 | 3 | <img src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.svg" alt="dotenv" align="right" width="200" /> |
4 | 4 |
|
5 | | -> Dotenv is a zero-dependency module that loads environment variables from a `.env` file into [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env). Storing configuration in the environment separate from code is based on [The Twelve-Factor App](https://12factor.net/config) methodology. |
6 | | -> |
7 | | -> [2 minute tutorial 📺](https://www.youtube.com/watch?v=YtkZR0NFd1g) |
| 5 | +Dotenv is a zero-dependency module that loads environment variables from a `.env` file into [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env). Storing configuration in the environment separate from code is based on [The Twelve-Factor App](https://12factor.net/config) methodology. |
8 | 6 |
|
9 | | -* [usage](#usage) |
10 | | -* [environments](#multiple-environments) |
11 | | -* [deploying](#deploying) |
12 | | -* [agents 🆕](#agents-as2) |
| 7 | +[Watch the tutorial](https://www.youtube.com/watch?v=YtkZR0NFd1g) |
13 | 8 |
|
14 | 9 | |
15 | 10 |
|
16 | | -### Usage |
| 11 | +## Usage |
17 | 12 |
|
18 | 13 | Install it. |
19 | 14 |
|
@@ -226,45 +221,6 @@ You need to deploy your secrets in a cloud-agnostic manner? Use [dotenvx](https: |
226 | 221 |
|
227 | 222 | </details> |
228 | 223 |
|
229 | | -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): |
230 | | - |
231 | | -```ini |
232 | | -S3_BUCKET="YOURS3BUCKET" |
233 | | -SECRET_KEY="YOURSECRETKEYGOESHERE" |
234 | | -``` |
235 | | - |
236 | | -As early as possible in your application, import and configure dotenv: |
237 | | - |
238 | | -```javascript |
239 | | -require('dotenv').config() |
240 | | -console.log(process.env) // remove this after you've confirmed it is working |
241 | | -``` |
242 | | - |
243 | | -.. [or using ES6?](#how-do-i-use-dotenv-with-import) |
244 | | - |
245 | | -```javascript |
246 | | -import 'dotenv/config' |
247 | | -``` |
248 | | - |
249 | | -ES6 import if you need to set config options: |
250 | | - |
251 | | -```javascript |
252 | | -import dotenv from 'dotenv' |
253 | | - |
254 | | -dotenv.config({ path: '/custom/path/to/.env' }) |
255 | | -``` |
256 | | - |
257 | | -That's it. `process.env` now has the keys and values you defined in your `.env` file: |
258 | | - |
259 | | -```javascript |
260 | | -require('dotenv').config() |
261 | | -// or import 'dotenv/config' if you're using ES6 |
262 | | - |
263 | | -... |
264 | | - |
265 | | -s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {}) |
266 | | -``` |
267 | | - |
268 | 224 | |
269 | 225 |
|
270 | 226 | ## Multiple Environments |
|
0 commit comments