db.js
// Keep data base connection live.
Keep data base connection live.
Keep data base connection live .
function handleDisconnect() {
    connection = mysql.createConnection(db_config); 
    connection.connect(function(err) {             
        if(err) {                                  
            console.log('error when connecting to db:', err);
            setTimeout(handleDisconnect, 2000);                
        }                                          
        else 
        	console.log('connected as id ' + connection.threadId);
    });                                             
    connection.on('error', function(err) {
        console.log('db error', err);
        if(err.code === 'PROTOCOL_CONNECTION_LOST') {   
            handleDisconnect();                         
        } 
        else {                                         
            throw err;
        }
    });
}
function handleDisconnect ( ) { connection = mysql . createConnection ( db_config ) ; connection . connect ( function ( err ) { if ( err ) { console . log ( 'error when connecting to db:' , err ) ; setTimeout ( handleDisconnect , 2000 ) ; } else console . log ( 'connected as id ' + connection . threadId ) ; } ) ; connection . on ( 'error' , function ( err ) { console . log ( 'db error' , err ) ; if ( err . code === 'PROTOCOL_CONNECTION_LOST' ) { handleDisconnect ( ) ; } else { throw err ; } } ) ; }
Keep data base connection live.
Keep data base connection live .