Created
January 24, 2020 10:56
-
-
Save amardeep18/80bc2e0487e7f8e5e34bf46690a8c2fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mysql = require('mysql'); | |
var db; var setting = { host : "localhost", user : "root", password : "", database : "crudapp" }; | |
function connectDatabase() { | |
if(!db) { | |
db = mysql.createConnection(setting); | |
db.connect(function (err) { | |
if(!err) { | |
console.log("Database connected") | |
; | |
} | |
else { | |
console.log("Error database connection") | |
} | |
}) | |
} | |
return db; | |
} | |
module.exports = connectDatabase(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment