Skip to content

Instantly share code, notes, and snippets.

@amardeep18
Created January 24, 2020 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amardeep18/80bc2e0487e7f8e5e34bf46690a8c2fa to your computer and use it in GitHub Desktop.
Save amardeep18/80bc2e0487e7f8e5e34bf46690a8c2fa to your computer and use it in GitHub Desktop.
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