-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDb.js
More file actions
32 lines (27 loc) · 812 Bytes
/
Db.js
File metadata and controls
32 lines (27 loc) · 812 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
29
30
31
32
//Dependencies...
const mysql = require('mysql2/promise');
require('dotenv').config();
//First Create a connection to the database,
const Connection = mysql.createPool(
{
host:process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database:process.env.DB_NAME,
port:process.env.DB_PORT,
waitForConnections:true,
connectionLimit:10,
queueLimit:0
}
);
//Let's check the connection Connection
const testConnection = async()=>{
try{
const connection = await Connection.getConnection();
console.log("Database connected successfully");
connection.release();
}catch(err){
console.log("Database connection failed "+err);
}
}
module.exports = {Connection,testConnection};