snglpi/config/databaseConfig.js

28 lines
891 B
JavaScript
Raw Permalink Normal View History

2025-08-30 19:04:35 -03:00
const { Sequelize } = require('sequelize');
require('dotenv').config();
// Database connection configuration
const dbConfig = {
host: process.env.DB_HOST,
dialect: process.env.DB_DIALECT || 'mysql', // Default to MySQL if not specified
logging: false, // Disable logging; set to console.log to enable
};
// Create a new Sequelize instance
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, dbConfig);
// Test the database connection
const testConnection = async () => {
try {
await sequelize.authenticate();
console.log('Connection to the database has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
};
// Export the sequelize instance and the test connection function
module.exports = {
sequelize,
testConnection,
};