node.js - Initilize method in node module -


in understanding node modules initialized when required first time. make initialization code optional. this:

mymodule.js:

module.exports.init=function(){   this.foo = 'initialized'; }; 

to achieve this:

var mymodule = require('./mymodule'); mymodule.foo === undefined; //true mymodule.init(); mymodule.foo === 'initialized'; // true 

or there possibility of modules getting reloaded (and thus, in case, uninitialized)?

thanks answers!

m

clarification: not want reload module. want module remain uninitialized until part of application explicitly. question is, node ever reload cached modules that, in example above, foo undefined though init has been called somewhere?


Comments

Popular posts from this blog

java - How to compare two classes -

javascript - Why Selenium can't find an element that is graphically visible -

c# - Get the Class name in a class with atribute inside a attribute method -