From 03c4155c4854bc4452a5a3448b8a58210b87c66c Mon Sep 17 00:00:00 2001 From: Maxence Date: Mon, 1 Apr 2024 11:47:06 +0200 Subject: [PATCH] add comment et modif import dotenv --- server/config/db.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/config/db.js b/server/config/db.js index ed98b2ed..a34bb99c 100644 --- a/server/config/db.js +++ b/server/config/db.js @@ -1,15 +1,15 @@ -const { config } = require("dotenv"); -const mongoose = require("mongoose"); +require("dotenv").config(); // this reads the .env file and sets the environment variables. +const mongoose = require("mongoose"); // this is the ODM for MongoDB -mongoose - .connect( +mongoose // this connects to the MongoDB database + .connect( // the connection string is stored in the .env file "mongodb+srv://" + process.env.DB_USER_PASS + - "@cluster0.v8rv1aj.mongodb.net/khagu-dev?retryWrites=true&w=majority", + "@cluster0.v8rv1aj.mongodb.net/khagu-dev?retryWrites=true&w=majority", // this is the connection string { - useNewUrlParser: true, - useUnifiedTopology: true, + useNewUrlParser: true, // these are some options to avoid deprecation warnings + useUnifiedTopology: true, // these are some options to avoid deprecation warnings } ) - .then(() => console.log("connected to MongoDB")) - .catch((err) => console.log("Failed to connect to MongoDB :", err)); + .then(() => console.log("connected to MongoDB")) // if the connection is successful, this message is printed + .catch((err) => console.log("Failed to connect to MongoDB :", err)); // if the connection fails, this message is printed