aboutsummaryrefslogtreecommitdiffstats
path: root/backend/src/config/database.js
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/config/database.js')
-rw-r--r--backend/src/config/database.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/backend/src/config/database.js b/backend/src/config/database.js
new file mode 100644
index 0000000..8fd758e
--- /dev/null
+++ b/backend/src/config/database.js
@@ -0,0 +1,14 @@
+const mongoose = require('mongoose');
+
+const connectDB = async () => {
+ try {
+ const conn = await mongoose.connect(process.env.MONGODB_URI || 'mongodb://localhost:27017/restaurant');
+ console.log(`MongoDB Connected: ${conn.connection.host}`);
+ return conn;
+ } catch (error) {
+ console.error(`Error: ${error.message}`);
+ process.exit(1);
+ }
+};
+
+module.exports = connectDB; \ No newline at end of file