Building Enterprise JavaScript Applications
上QQ阅读APP看书,第一时间看更新

The birth of Node.js modules

Using modules on the client was infeasible because an application can have hundreds of dependencies and sub-dependencies; having to download them all when someone visits the page is going to increase the time-to-first-render (TTFR), drastically impacting the user experience (UX). Therefore, JavaScript modules, as we know them today, began their ascent on servers with Node.js modules.

In Node.js, a single file corresponds to a single module:

$ tree
.
├── greeter.js
└── main.js
0 directories, 2 files

For instance, both of the preceding filesgreeter.js and main.jsare each their own module.