Short answer, English is not my strong point ;-) A keyword: modularization
Instead of populate the global environment, each module exposes the functions that needed to be consumed, without worrying of name conflicts with other modules. And there are more benefits: - Each module tries to cover a single domain of problem, module trends to be small in node.js ecosystem (except if it is a framework) - The internal representation is in the module, only the top of the iceberg is exposed via module.exports - Notably, you will see few classes exposes. Instead of "new mymodule.MyClass()" you will see "mymodule.createObject(...)", factory methods, that encapsulates the real implementation Don't forget the NPM and versioning system: each module can consume exactly the required version of other module. Then, A could consume [email protected], and C could consume [email protected], without problem. If B module populated the global environment, such separation could not be possible. NPM is the "secret weapon" in Node.js ecosystem. Paraphrasing David Hilbert: "No one will drive us from the paradise which Node.js modules created for us" Angel "Java" Lopez @ajlopez On Thu, Oct 2, 2014 at 5:20 AM, Sameer Joshi <[email protected]> wrote: > Hello Team! > > I wanted to know, what are the advantages (if there are) of calling > functions from modules using *modules.exports* as opposed adding all the > functions to the main app JS file. > > I am looking for a simple comparison or pro's and con's for points apart > from that it gives logical modularity and readability. > > Thanks a ton! > > -- > Job board: http://jobs.nodejs.org/ > New group rules: > https://gist.github.com/othiym23/9886289#file-moderation-policy-md > Old group rules: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/nodejs/1503ae1e-db83-46c7-968f-65896a9e618c%40googlegroups.com > <https://groups.google.com/d/msgid/nodejs/1503ae1e-db83-46c7-968f-65896a9e618c%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAMs%2BDq%2B406dR5avW7EEK-qFLKgD%2BkqGJwmA8whgp6D78EP4Emw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
