UNPKG

men-pack

Version:

men-pack is a collection of funcationalities that can helps developers to easily develop MongoDB Express Node Applications/Backend

41 lines (40 loc) 1.28 kB
"use strict"; // import mongoose from "mongoose"; // class MongoDBClient { // private isConnected = false; // async connect(uri: string): Promise<void> { // if (this.isConnected) { // console.log("Already connected to MongoDB."); // return; // } // try { // await mongoose.connect(uri); // this.isConnected = true; // console.log("Connected to MongoDB successfully."); // } catch (error) { // console.error("Error connecting to MongoDB:", error); // throw error; // } // } // async disconnect(): Promise<void> { // if (!this.isConnected) { // console.log("No active MongoDB connection to disconnect."); // return; // } // try { // await mongoose.disconnect(); // this.isConnected = false; // console.log("Disconnected from MongoDB successfully."); // } catch (error) { // console.error("Error disconnecting from MongoDB:", error); // throw error; // } // } // } // const mongoDBClient = new MongoDBClient(); // export const connectToMongoDB = async (uri: string): Promise<void> => { // await mongoDBClient.connect(uri); // }; // export const disconnectFromMongoDB = async (): Promise<void> => { // await mongoDBClient.disconnect(); // };