Edit Fork Copy function MVC(){ this.mysql= require('mysql'); this.host=''; this.user=''; this.password=''; this.database=''; this.connected = function(host, user, password){ this.host=host; this.user=user; this.password=password; this.conn=this.mysql.createConnection({ host: this.host, user: this.user, password: this.password }); this.conn.connect(function(err){ if(err) throw err; console.log('Connected'); }) } this.databased= function(){ if(this.connected){ this.conn.query("Create database mydb", function(err, result){ if(err) throw err; console.log("DB created"); console.log(result); }) } } this.crTable= function(){ if(this.connected){ this.conn.query("CREATE TABLE customers (name VARCHAR(255), address VARCHAR(255))", function(err, result){ if (err) throw err; console.log("Table created"); }) } } this.inserted= function(){ if(this.connected){ this.conn.query("Insert into customers (name, address) VALUES ('Company Inc', 'Highway 37')", function(err, result){ if(err) throw err; console.log("1 Record inserted"); }) } } }; function MVC2 var demo= new MVC(); demo.connected("localhost","root",""); demo.databased("create database mydb"); // demo.crTable();