-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7492503
commit 9c54ec4
Showing
5 changed files
with
40 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import mongoose from "mongoose"; | ||
import dotenv from "dotenv"; | ||
|
||
dotenv.config(); // Load environment variables from .env file | ||
|
||
const dbConnection = async () => { | ||
try { | ||
const dbConnection = await mongoose.connect(process.env.MONGODB_URL); | ||
console.log("Database connected successfully"); | ||
const dbUri = process.env.MONGO_URL; | ||
if (!dbUri) { | ||
throw new Error("MONGO_URL environment variable is not set."); | ||
} | ||
|
||
await mongoose.connect(dbUri, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}); | ||
|
||
console.log("Database connected successfully"); | ||
} catch (error) { | ||
console.log('MongoConnection Failed !!' + error ); | ||
console.log('MongoConnection Failed !! ' + error); | ||
} | ||
} | ||
|
||
export default dbConnection; | ||
export default dbConnection; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters