javascript - compile order of node.js modules -
the problem have number of separate modules export using module.exports , inter dependent. say-
mongohelper transaction server conhandlr appmin now, server module contains common object required other 4 modules. however, when compiling node app, of these modules compiled before server module example using console output found order -
compile order- mongohelper transaction server (..the upper modules have undefined common object now) conhandlr appmin so, there way can make sure server module compiles first dependent modules dont have undefined objects?
without actual code, it's hard understand want know, i'll try give basic understanding of how node modules work.
require("module") synchronous call. complete module evaluated/"compiled" before parser goes on next line of code. means, dependencies executed in order specified. executed once per process. means, if you're requiring same module multiple times, executed @ first time , module.exports cached.
i suggest reading docs.
Comments
Post a Comment