Answer the question
In order to leave comments, you need to log in
How to make a generic Node JS module?
There is a database module
function createBD(){
console.log('create BD');
};
exports.createBD = createBD;
Answer the question
In order to leave comments, you need to log in
function createBD(){
console. log('create BD');
};
module.exports = new createDB();
var bd = new bd.createBD();
//update: SomeModule - загруженный через require модуль
var mModule = new SomeModule(bd);
var lDb = undefined;
module.exports = function(dbObject)
{
// как-то проверяем значение dbObject. Если не допустимое значение - ошибка
lDb = dbObject;// внутренний объект bd
// тут объекты, методы текущего модуля
...
}
Use the Global, Luke!
// In application entry point or framework
global.api = {};
api.fs = require('fs');
api.http = require('http');
require('./db');
require('./application');
global.db = new api.db.createDatabase();
// In DB module: db.js
api.db = {};
api.db.createDatabase = function() {
console.log('Create DB');
};
// In any place and any applied module
db.select('.....or whatever you want');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question