-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnection.js
34 lines (29 loc) · 912 Bytes
/
connection.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
// *********************************************************************************
// CONNECTION.JS - THIS FILE INITIATES THE CONNECTION TO MYSQL
// *********************************************************************************
// Require mysql
var mysql = require("mysql");
// Set up our connection information
var connection;
if (process.env.NODE_ENV === "production") {
const connectionString = process.env.JAWSDB_URL;
connection = mysql.createConnection(connectionString);
} else {
connection = mysql.createConnection({
port: 3306,
host: "127.0.0.1",
user: "tetrisuser",
password: "tetris",
database: "tetris"
});
}
// Connect to the database
connection.connect(function(err) {
if (err) {
console.error("error connecting: " + err.stack);
return;
}
console.log("connected as id " + connection.threadId);
});
// Export connection
module.exports = connection;