Skip to content

Commit

Permalink
add comment et modif import dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
Khagou committed Apr 1, 2024
1 parent bc74dee commit 03c4155
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions server/config/db.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 03c4155

Please sign in to comment.