-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathdbConnection.js
More file actions
26 lines (24 loc) · 801 Bytes
/
Copy pathdbConnection.js
File metadata and controls
26 lines (24 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import mongoose from "mongoose";
// export const dbConnection = ()=>{
// mongoose
// .connect(process.env.MONGO_URI,{
// dbName: "RESTAURANT",
// })
// .then(()=>{
// console.log("Connected to database is Successful");
// })
// .catch((err)=>{
// console.log(`Some error occured while connecting to Database! ${err}`);
// });
// };
export const dbConnection = async () => {
try {
await mongoose.connect(process.env.MONGO_URI, {
dbName: "RESTAURANT",
});
console.log("Connected to database successfully");
} catch (err) {
console.error(`Error connecting to the database: ${err.message}`);
throw err; // Or handle it with your error middleware
}
};