25 lines
714 B
JavaScript
25 lines
714 B
JavaScript
const mysql = require('mysql2/promise');
|
|
require('dotenv').config();
|
|
|
|
const pool = mysql.createPool({
|
|
host: process.env.DB_HOST,
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASS,
|
|
database: process.env.DB_DATABASE,
|
|
port: process.env.DB_PORT,
|
|
waitForConnections: true,
|
|
connectionLimit: 10,
|
|
queueLimit: 0
|
|
});
|
|
|
|
async function testConnection() {
|
|
try {
|
|
const connection = await pool.getConnection();
|
|
console.log('Successfully connected to the database !');
|
|
connection.release();
|
|
} catch (error) {
|
|
console.error('Failed to connect to the database:', error.message);
|
|
}
|
|
}
|
|
|
|
module.exports = { pool, testConnection }; |