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

android - Basic camera in app -

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

scala - Using the kronecker product on complex matrices with scalaNLP breeze -