Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

---
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
"test": "jest",
"prepare": "husky install"
},
"mongodbMemoryServer": {
"version": "7.0.14"
},
"dependencies": {
"bcryptjs": "2.4.3",
"compression": "1.7.4",
Expand Down
21 changes: 20 additions & 1 deletion src/config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export const connectDatabase = async (): Promise<void> => {
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');

Expand All @@ -17,6 +22,20 @@ export const connectDatabase = async (): Promise<void> => {
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);
Expand Down
Loading