Getting Started
A commonJS module system is followed by Node.js. The modules which are present in separate files need to be included. And for importing them, there exist some methods in node.js like: “require” and “ES6 import and export”.
Let’s have a close look at them.

Source: Giphy
Require:
It exists as a built-in function in node.js. Using require, the modules that exist in the files can be included easily. It can read a Javascript file, execute the file and then return the export object. It allows built-in core Node modules, local modules, and also community-based modules. These are nothing but built-in modules like HTTP module, URL module, path module, and a lot more.
Syntax:
The inbuilt module can be included as:
| const express = require('express'); |
The local module can be included as:
The abc module path is required here in this example, which can be used without specifying a way.
| require('abc'); |
The node will look for abc.js in the path specified by module.paths in order.
ES6 import and export
Both import and export statements are used to refer to the ES module. Other file types can’t be imported with these statements. These are only prioritized in ES modules where its specifier can only be a URL-style relative path or a package name.
But export statements permit the user to export its created objects and methods to other programs. Let’s consider; if any string lateral is taken, then it will be exposed as a module.





