-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.js
39 lines (30 loc) · 1.04 KB
/
database.js
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
38
39
/*
A file that connects to the MySQL instance on Google Cloud. Credentials stored in a seperate local file unlinked to version control.
*/
const mysql = require('mysql');
require('dotenv').config();
// Database Connection for Production
// let config = {
// user: process.env.SQL_USER,
// database: process.env.SQL_DATABASE,
// password: process.env.SQL_PASSWORD,
// }
// if (process.env.INSTANCE_CONNECTION_NAME && process.env.NODE_ENV === 'production') {
// config.socketPath = `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`;
// }
// let connection = mysql.createConnection(config);
let connection = mysql.createConnection({
host: process.env.DB_HOST,
instance_name: process.env.DB_INSTANCE_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_DATABASE
});
connection.connect(function(err){
if (err){
console.log("Error connecitng to db: " + err.stack);
return;
}
console.log("Connected to db as thread id: " + connection.threadId);
});
module.exports = connection;