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
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -519,7 +519,7 @@ We also added the hardcoded port of the server into the <em>PORT</em> environmen
519
519
520
520
The environment variables defined in the <i>.env</i> file can be taken into use with the expression <em>require('dotenv').config()</em> and you can reference them in your code just like you would reference normal environment variables, with the <em>process.env.MONGODB_URI</em> syntax.
521
521
522
-
Let's change the <i>index.js</i> file in the following way:
522
+
Let's load the environment variables at the beginning of the index.js file so that they are available throughout the entire application. Let's change the <i>index.js</i> file in the following way:
Copy file name to clipboardExpand all lines: src/content/3/fi/osa3c.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -464,10 +464,6 @@ Näin muuttuja _Note_ saa arvokseen saman olion, jonka moduuli määrittelee.
464
464
Yhteyden muodostustavassa on pieni muutos aiempaan:
465
465
466
466
```js
467
-
consturl=process.env.MONGODB_URI
468
-
469
-
console.log('connecting to', url)
470
-
471
467
mongoose.connect(url)
472
468
.then(result=> {
473
469
console.log('connected to MongoDB')
@@ -477,12 +473,18 @@ mongoose.connect(url)
477
473
})
478
474
```
479
475
480
-
Tietokannan osoitetta ei kannata kirjoittaa koodiin, joten osoite annetaan sovellukselle ympäristömuuttujan <em>MONGODB_URI</em> välityksellä.
481
-
482
476
Yhteyden muodostavalle metodille on nyt rekisteröity onnistuneen ja epäonnistuneen yhteydenmuodostuksen käsittelevät funktiot, jotka tulostavat konsoliin tiedon siitä, onnistuiko yhteyden muodostaminen:
483
477
484
478

485
479
480
+
Ei ole myöskään hyvä idea kovakoodata tietokannan osoitetta koodiin, joten tietokannan osoite välitetään sovellukselle <em>MONGODB_URI</em> ympäristömuuttujan kautta:
481
+
482
+
```js
483
+
consturl=process.env.MONGODB_URI
484
+
485
+
console.log('connecting to', url)
486
+
```
487
+
486
488
On useita tapoja määritellä ympäristömuuttujan arvo. Voimme esim. antaa sen ohjelman käynnistyksen yhteydessä seuraavasti:
487
489
488
490
```bash
@@ -512,7 +514,7 @@ Määrittelimme samalla aiemmin kovakoodaamamme sovelluksen käyttämän portin
512
514
513
515
dotenvissä määritellyt ympäristömuuttujat otetaan koodissa käyttöön komennolla <em>require('dotenv').config()</em> ja niihin viitataan Nodessa kuten "normaaleihin" ympäristömuuttujiin syntaksilla <em>process.env.MONGODB_URI</em>.
514
516
515
-
Muutetaan nyt tiedostoa <i>index.js</i> seuraavasti:
517
+
Ladataan ympäristömuuttujat käyttöön heti <i>index.js</i>-tiedoston alussa, jolloin ne tulevat käyttöön koko sovellukselle. Muutetaan nyt tiedostoa <i>index.js</i> seuraavasti:
0 commit comments