Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// /config/db.js
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const config = require('./config');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
const connectDB = async () => {
|
||||
try {
|
||||
const conn = await mongoose.connect(config.MONGO_URI, {
|
||||
autoIndex: true
|
||||
});
|
||||
logger.info(`MongoDB Connected: ${conn.connection.host}`);
|
||||
} catch (error) {
|
||||
logger.error(`Database connection error: ${error.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
mongoose.connection.on('disconnected', () => {
|
||||
logger.warn('MongoDB disconnected. Attempting to reconnect...');
|
||||
});
|
||||
|
||||
mongoose.connection.on('error', (err) => {
|
||||
logger.error(`MongoDB connection error: ${err.message}`);
|
||||
});
|
||||
|
||||
module.exports = connectDB;
|
||||
Reference in New Issue
Block a user