summaryrefslogtreecommitdiff
path: root/backend/src/config
diff options
context:
space:
mode:
authorDaniel Andreas Wang <danielaw@relvokcor.xyz>2026-03-14 15:37:31 +0100
committerDaniel Andreas Wang <danielaw@relvokcor.xyz>2026-03-14 15:37:31 +0100
commitf4f6f490ab0bb1a2a06d660ce1b276a4fad9d2c2 (patch)
tree9c9af5b4f49274fd1a62627b8879caf616d25a93 /backend/src/config
first commitHEADmain
Diffstat (limited to 'backend/src/config')
-rw-r--r--backend/src/config/constants.js1
-rw-r--r--backend/src/config/database.js17
2 files changed, 18 insertions, 0 deletions
diff --git a/backend/src/config/constants.js b/backend/src/config/constants.js
new file mode 100644
index 0000000..d7f4ed1
--- /dev/null
+++ b/backend/src/config/constants.js
@@ -0,0 +1 @@
+export const DB_NAME = 'intro-to-backend'; \ No newline at end of file
diff --git a/backend/src/config/database.js b/backend/src/config/database.js
new file mode 100644
index 0000000..98ce0cc
--- /dev/null
+++ b/backend/src/config/database.js
@@ -0,0 +1,17 @@
+import mongoose from "mongoose";
+import { DB_NAME } from './constants.js'
+
+const connectDB = async () => {
+ try {
+ const connectionInstance = await mongoose.connect(
+ `${process.env.MONGODB_URI}/${DB_NAME}`,
+ );
+ console.log(`\nMongoDB connected successfully
+ ${connectionInstance.connection.host}`)
+ } catch (error) {
+ console.log("MongoDB connection failed", error)
+ process.exit(1)
+ }
+}
+
+export default connectDB