I’m trying to develop a class with static methods on a NodeJs application, as a Config module purpose.
I would like to access to it from different modules without instantiate every time a new object.
1) Is it correct to use an approach like below, avoiding the class prototype?
function Config(){
}
Config.svrPort=function(){
return 8080;
}
Config.dbName=function(){
return "myDbName";
}
module.exports = Config;
2) Are there any other solutions?
3) Is it also a valid approach to put different objects in the same module (e.g. config.js) like this?
exports.server=function(){
return{
port:8080
};
};
exports.database=function(){
return{
name:"myDbName",
user:"root",
password:"myPassword",
host:"localhost",
port:3306
};
};
and finally to use it as:
var config = require('./config');
config.server().port
config.database().name