Share:- Whatsapp Facebook Facebook

------------------------------------- Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

What is a Module in Node.js

0 votes
37 views
What is a Module in Node.js?
asked Sep 1, 2017 in Node.js by Sujeet Jha

1 Answer

0 votes
In node.js consider modules same as JavaScript libraries. It is a set of functions you want to include in our application.
Each module in Node.js has its own context, so it cannot interfere with other modules or pollute global scope. Also, each module can be placed in a separate js file under a separate folder.

Node.js implements CommonJS modules standard. CommonJS defines JavaScript standards for web server, desktop, and console application.

There are three types of modules in Node.js: -

    1. Core Modules (Built-in Modules):- Node.js has set of built-in modules which we can use without any further installation. For Example:-
        var http = require('http');
    2. Local Modules (Own Modules):- You can create your own modules and easily include them in applications. For Example:-
        exports.myDTe = function () {
            return Date();
        };
    3. Third Party Modules:-

Include Modules:- To include a module use require() function with the name of module. For Example:-
var http = require('http');
answered Sep 1, 2017 by ranju_12 (3,740 points)
...