Skip to content

Commit 2ae52b8

Browse files
committed
update README
1 parent 2cf362a commit 2ae52b8

1 file changed

Lines changed: 49 additions & 11 deletions

File tree

README.md

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@
44

55
 
66

7-
# dotenv [![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv)
7+
# dotenv [![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv) [![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) [![codecov](https://codecov.io/gh/motdotla/dotenv-expand/graph/badge.svg?token=pawWEyaMfg)](https://codecov.io/gh/motdotla/dotenv-expand)
88

99
<img src="https://raw.githubusercontent.com/motdotla/dotenv/master/dotenv.svg" alt="dotenv" align="right" width="200" />
1010

1111
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.
1212

13-
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
14-
[![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE)
15-
[![codecov](https://codecov.io/gh/motdotla/dotenv-expand/graph/badge.svg?token=pawWEyaMfg)](https://codecov.io/gh/motdotla/dotenv-expand)
13+
&nbsp;
1614

17-
* [Install](#install)
18-
* [Usage](#usage)
19-
* [Multiple Environments](#multiple-environments)
20-
* [Deploying](#deploying)
21-
* [Agents (AS2) 🆕](#agents-as2)
15+
### Quickstart
2216

23-
## Install
17+
Install and use it in code just like `dotenv`.
2418

25-
```bash
19+
```sh
2620
npm install dotenv --save
2721
```
2822

@@ -34,8 +28,52 @@ bun add dotenv
3428
pnpm add dotenv
3529
```
3630

31+
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+
import dotenv from '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:
60+
61+
```javascript
62+
require('dotenv').config()
63+
// or import 'dotenv/config' if you're using ES6
64+
65+
...
66+
67+
s3.getBucketCors({Bucket: process.env.S3_BUCKET}, function(err, data) {})
68+
```
69+
3770
&nbsp;
3871

72+
* [Usage](#usage)
73+
* [Multiple Environments](#multiple-environments)
74+
* [Deploying](#deploying)
75+
* [Agents (AS2) 🆕](#agents-as2)
76+
3977
## Usage
4078

4179
<a href="https://www.youtube.com/watch?v=YtkZR0NFd1g">

0 commit comments

Comments
 (0)