(Feat): Initial Commit
This commit is contained in:
33
backend/config/database.js
Normal file
33
backend/config/database.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import mysql from 'mysql2/promise';
|
||||
import dotenv from 'dotenv';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname, join } from 'path';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Load .env from backend directory
|
||||
dotenv.config({ path: join(__dirname, '..', '.env') });
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
user: process.env.DB_USER || 'root',
|
||||
password: process.env.DB_PASSWORD || 'admin123',
|
||||
database: process.env.DB_NAME || 'work_allocation',
|
||||
port: process.env.DB_PORT || 3306,
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
});
|
||||
|
||||
// Test connection
|
||||
pool.getConnection()
|
||||
.then(connection => {
|
||||
console.log('✅ Database connected successfully');
|
||||
connection.release();
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('❌ Database connection failed:', err.message);
|
||||
});
|
||||
|
||||
export default pool;
|
||||
Reference in New Issue
Block a user