firstly, my English skill is poor i`m sorry about that
i made this code for hide private functions & vars from other
DB_OBJ.js
module.exports = (function() {
var _mysql = require('mysql');
var _self = null;
var _connFlag = false;
var _mysqlConfig = {
host: "127.0.0.1",
port: 3306,
user: "tester",
password: "*****",
database: "*****"
};
var _conn = null;
var _init = function(){
_conn = _mysql.createConnection(_mysqlConfig);
_conn.connect(function(err) {
if (err) {
console.log(err);
}
_connFlag = true;
});
};
var db_obj = function (args) {
_self = this;
if (args) {
_mysqlConfig.host = (args["host"]) ? args["host"] : "127.0.0.1";
_mysqlConfig.port = (args["port"]) ? args["port"] : "3306";
_mysqlConfig.user = (args["user"]) ? args["user"] : "*****";
_mysqlConfig.password = (args["password"]) ? args["password"] : "*****";
_mysqlConfig.database = (args["database"]) ? args["database"] : "*****";
}
this.init = function () {
_init();
};
};
return db_obj;
})();
main.js
var db_obj = new require('./DB_OBJ');
db_obj.init();
but this code error occur it:
TypeError: db_obj.init is not a function
please. let me know how can i fix it?
Thanks.