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

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -