-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdatabase.js
More file actions
37 lines (30 loc) · 842 Bytes
/
database.js
File metadata and controls
37 lines (30 loc) · 842 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
33
34
35
36
37
var mysql = require("mysql");
const fs = require('fs');
//Get credentials from configuration file
var config = require('./config.json')
var { database_ip, database_user, database_password, database_port, database } = config
//create connection to MySQL database
var con = mysql.createConnection({
host: database_ip,
database: database,
user: database_user,
password: database_password,
port: database_port,
multipleStatements: true
});
function connect(){
//connect to MySQL database
con.connect(function(err) {
if (err) {
console.error('Error connecting: ' + err.stack);
connect()
}
console.log('Connected as ID: ' + con.threadId);
});
}
connect()
//keep the connection running
setInterval(() => {
con.query('SELECT 1', (err, results) => {})
},5000)
module.exports = con;