import mongoose from "mongoose"; import { dbName, dbUrl } from "./env"; import Logger from "../utils/logger"; const connectDB = async () => { try { await mongoose .connect(dbUrl,{ dbName: dbName }) .then((data: any) => // Logger.info(`🗄️ ==> '${data.connection.host}/${dbName}' DB is Connected. `) logDb() ); } catch (error : any) { Logger.error(`🗄️ ==> Unable to connect db : `) Logger.error(error.message) // setTimeout(connectDB, 5000); process.exit(1); } }; const logDb = () => { const msg = `🗄️ DB is Connected.`; const length = msg.length + 4; const n = Math.floor((length - msg.length) / 2); Logger.log(' ' + '-'.repeat(length)); Logger.log(`|${' '.repeat(n)}${msg}${' '.repeat(n)} |`); Logger.log(' ' + '-'.repeat(length)); } export default connectDB;