Skip to content

Commit bc9b38b

Browse files
authored
Merge pull request #3936 from ElenaCM-0/patch-2
Changing the .env references
2 parents 09107b3 + 36e54c7 commit bc9b38b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/content/3/en/part3c.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,6 @@ This way the _Note_ variable will be assigned to the same object that the module
471471
The way that the connection is made has changed slightly:
472472

473473
```js
474-
const url = process.env.MONGODB_URI
475-
476-
console.log('connecting to', url)
477-
478474
mongoose.connect(url)
479475
.then(result => {
480476
console.log('connected to MongoDB')
@@ -484,12 +480,18 @@ mongoose.connect(url)
484480
})
485481
```
486482

487-
It's not a good idea to hardcode the address of the database into the code, so instead the address of the database is passed to the application via the <em>MONGODB_URI</em> environment variable.
488-
489483
The method for establishing the connection is now given functions for dealing with a successful and unsuccessful connection attempt. Both functions just log a message to the console about the success status:
490484

491485
![node output when wrong username/password](../../images/3/45e.png)
492486

487+
It's also not a good idea to hardcode the address of the database into the code, so the url is obtained differently: the address of the database is passed to the application via the <em>MONGODB_URI</em> environment variable:
488+
489+
```js
490+
const url = process.env.MONGODB_URI
491+
492+
console.log('connecting to', url)
493+
```
494+
493495
There are many ways to define the value of an environment variable. One way would be to define it when the application is started:
494496

495497
```bash

0 commit comments

Comments
 (0)