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
Copy file name to clipboardExpand all lines: src/content/3/en/part3c.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -471,10 +471,6 @@ This way the _Note_ variable will be assigned to the same object that the module
471
471
The way that the connection is made has changed slightly:
472
472
473
473
```js
474
-
consturl=process.env.MONGODB_URI
475
-
476
-
console.log('connecting to', url)
477
-
478
474
mongoose.connect(url)
479
475
.then(result=> {
480
476
console.log('connected to MongoDB')
@@ -484,12 +480,18 @@ mongoose.connect(url)
484
480
})
485
481
```
486
482
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
-
489
483
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:
490
484
491
485

492
486
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
+
consturl=process.env.MONGODB_URI
491
+
492
+
console.log('connecting to', url)
493
+
```
494
+
493
495
There are many ways to define the value of an environment variable. One way would be to define it when the application is started:
0 commit comments