diff --git a/README.md b/README.md index 7f142ef..27cd678 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # SwiftChain_Backend -setup linked: 1,3,2 - **SwiftChain_Backend** is the core API service for **SwiftChain**, a Blockchain-Powered Logistics & Escrow Delivery Platform. It connects individuals, businesses, and independent drivers in a decentralized logistics economy, ensuring trust through escrow payments and smart contracts. --- diff --git a/package.json b/package.json index 505cd6f..cc3e786 100644 --- a/package.json +++ b/package.json @@ -15,9 +15,6 @@ "test": "jest", "prepare": "husky install" }, - "mongodbMemoryServer": { - "version": "7.0.14" - }, "dependencies": { "bcryptjs": "2.4.3", "compression": "1.7.4", diff --git a/src/config/database.ts b/src/config/database.ts index caf1b2e..a0e9e4a 100644 --- a/src/config/database.ts +++ b/src/config/database.ts @@ -6,7 +6,12 @@ export const connectDatabase = async (): Promise => { try { const mongoUri = env.MONGODB_URI; - await mongoose.connect(mongoUri); + await mongoose.connect(mongoUri, { + maxPoolSize: 10, // Maximum number of connections in the pool + minPoolSize: 2, // Minimum number of connections in the pool + serverSelectionTimeoutMS: 5000, // Timeout after 5s instead of 30s + socketTimeoutMS: 45000, // Close sockets after 45s of inactivity + }); logger.info('✅ Connected to MongoDB successfully'); @@ -17,6 +22,20 @@ export const connectDatabase = async (): Promise => { mongoose.connection.on('disconnected', () => { logger.warn('MongoDB disconnected'); }); + + mongoose.connection.on('reconnected', () => { + logger.info('✅ MongoDB reconnected'); + }); + + mongoose.connection.on('connected', () => { + logger.info(`MongoDB connected to ${mongoose.connection.host}`); + }); + + process.on('SIGINT', async () => { + await mongoose.connection.close(); + logger.info('MongoDB connection closed through app termination'); + process.exit(0); + }); } catch (error) { logger.error('❌ Failed to connect to MongoDB:', error); process.exit(1);