May 2018
Intermediate to advanced
492 pages
12h 3m
English
We've already seen a couple of examples of this module format, with the simple.js example, and the programs we examined in Chapter 2, Setting up Node.js. So let's take a closer look.
CommonJS modules are stored in files with the extension .js.
Loading a CommonJS module is a synchronous operation. That means that when the require('modulename') function call returns, the module has been located and completely read into memory and is ready to go. The module is cached in memory so that subsequent require('modulename') calls return immediately, and all return the exact same object.
Node.js modules provide a simple encapsulation mechanism to hide implementation details while exposing an API. Modules are treated as ...
Read now
Unlock full access