-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb.js
More file actions
28 lines (24 loc) · 853 Bytes
/
db.js
File metadata and controls
28 lines (24 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const { Sequelize } = require('sequelize');
require('dotenv').config(); // For loading environment variables from .env file
// Create a Sequelize instance with DB configuration
const sequelize = new Sequelize(
process.env.DB_NAME, // Database name
process.env.DB_USER, // Database username
process.env.DB_PASSWORD, // Database password
{
host: process.env.DB_HOST,
port: process.env.DB_PORT,
dialect: 'mariadb', // Database dialect, can be 'mysql', 'mariadb', 'postgres', etc.
}
);
// Test the connection
async function testConnection() {
try {
await sequelize.authenticate();
console.log('✅ Connection established successfully.');
} catch (error) {
console.error('❌ Unable to connect to the database:', error);
}
}
testConnection();
module.exports = sequelize;