CommonJS - Node.js

suggest change

CommonJS is a popular modularization pattern that’s used in Node.js.

The CommonJS system is centered around a require() function that loads other modules and an exports property that lets modules export publicly accessible methods.

Here’s an example of CommonJS, we’ll load Lodash and Node.js’ fs module:

// Load fs and lodash, we can use them anywhere inside the module
var fs = require("fs"),
    _ = require("lodash");

var myPrivateFn = function(param) {
    return "Here's what you said: " + param;
};

// Here we export a public `myMethod` that other modules can use
exports.myMethod = function(param) {
    return myPrivateFn(param);
};

You can also export a function as the entire module using module.exports:

module.exports = function() {
    return "Hello!";
};

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Modularization techniques:
* CommonJS - Node.js

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
85 Modularization techniques
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde