Skip to content

Commit 701f5a9

Browse files
committed
dotenv Package
1 parent db1aa58 commit 701f5a9

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,7 @@ app.listen(3000, function(){
25432543
<b><a href="#">↥ back to top</a></b>
25442544
</div>
25452545

2546-
## Q. ***Explain the terms body-parser, cookie-parser, morgan, nodemon, pm2, serve-favicon, cors, .env, checksum, fs-extra, moment in Express JS?***
2546+
## Q. ***Explain the terms body-parser, cookie-parser, morgan, nodemon, pm2, serve-favicon, cors, dotenv, checksum, fs-extra, moment in Express JS?***
25472547

25482548
**a) body-parser**
25492549

@@ -2752,6 +2752,38 @@ app.listen(8080, function () {
27522752
})
27532753
```
27542754

2755+
**h) dotenv**
2756+
2757+
When a NodeJs application runs, it injects a global variable called `process.env` which contains information about the state of environment in which the application is running. The `dotenv` loads environment variables stored in the `.env` file into `process.env`.
2758+
2759+
**Installation**
2760+
2761+
```bash
2762+
npm install dotenv
2763+
```
2764+
2765+
**Example**
2766+
2767+
**.env**
2768+
2769+
```js
2770+
DB_HOST=localhost
2771+
DB_USER=admin
2772+
DB_PASS=root
2773+
```
2774+
2775+
**Config.js**
2776+
2777+
```js
2778+
const db = require('db')
2779+
2780+
db.connect({
2781+
host: process.env.DB_HOST,
2782+
username: process.env.DB_USER,
2783+
password: process.env.DB_PASS
2784+
})
2785+
```
2786+
27552787
<div align="right">
27562788
<b><a href="#">↥ back to top</a></b>
27572789
</div>

0 commit comments

Comments
 (0)