/* Copyright © 2016 Stefano Pigozzi, Emiliano Maccaferri * Released under the GPL v3 license */ var mysql = require("mysql"); var fs = require("fs"); var config = JSON.parse(fs.readFileSync("config.json", "utf8")); var connection = mysql.createConnection({ host: config.host, password: config.db_pass, user: config.db_user, database: config.database }); function connect(){ connection.connect(function(err){ if(!err){ console.log("API connessa al database MySQL!"); }else{ console.log("Errore durante la connessione!", err); connection.end(); } }); connection.on('error', function(err) { console.log('db error', err); connection.end(); connection = mysql.createConnection({ host: config.host, password: config.db_pass, user: config.db_user, database: config.database }); connect(); }); } connect(); module.exports = connection;