Modules are frequently used techniques which is an important part of decoupling and make the code more readable and organised.
Module in NodeJS
In NodeJS, keywords
required are exploited to create/import a module. Here are three ways of creating a module. Some examples:
Module in ES6
In ES6, we can export
class as modules:
import keyword is from ES6, but not natively supported by NodeJS yet, so in order to make the following code work, we use
babel to compile it first.