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
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.
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):
32
+
33
+
```dosini
34
+
S3_BUCKET="YOURS3BUCKET"
35
+
SECRET_KEY="YOURSECRETKEYGOESHERE"
36
+
```
37
+
38
+
As early as possible in your application, import and configure dotenv:
39
+
40
+
```javascript
41
+
require('dotenv').config()
42
+
console.log(process.env) // remove this after you've confirmed it is working
43
+
```
44
+
45
+
.. [or using ES6?](#how-do-i-use-dotenv-with-import)
46
+
47
+
```javascript
48
+
import'dotenv/config'
49
+
```
50
+
51
+
ES6 import if you need to set config options:
52
+
53
+
```javascript
54
+
importdotenvfrom'dotenv'
55
+
56
+
dotenv.config({ path:'/custom/path/to/.env' })
57
+
```
58
+
59
+
That's it. `process.env` now has the keys and values you defined in your `.env` file:
0 commit comments