In this video we are going to learn about the module.
Module in Node.js is a simple or complex functionality organized in single or multiple JavaScript files.
Which can be reused throughout the Node.js application.
Each module in Node.js has its own context, so it cannot interfere with other modules.
Also, each module can be placed in a separate .js file under a separate folder.
Lets see the module.
So switch to the project and here create a new file lets say file name is calc.js.
Inside this file create a function expression.


var sum = function(num1,num2){
return num1+num2;
}


Now export this funciton through the module.export object.
The module.exports is a special object which is included in every JS file.
In Node.js application by default module is a variable that represents current module and exports is an object that will be exposed as a module.
So, whatever you assign to module.exports, will be exposed as a module.
For exporting module just write


module.export = sum


Now use this inside the index.js file.
So goto the index.js file here.
First of all require calc.js file here.


var sum = require('./calc');


Now just use this sum function.


console.log(sum(25,50));


Now lets run this.
So goto the command prompt and run the command.


node index.js


you will see the sum of the numbers.

You can also attach an object to module.exports.
Lets see so create a new file.
Lets say file name is data.js.
Inide this data.js file.
Just export an object.


module.export = {
name:\"Jenifer\",
email:jenifer@gmail.com,
phone:\"1234567890\"
}


Now use this inside the index.js file.


var data = require('./data');


Now just print the data.

console.log(data.name);
console.log(data.email);
cosole.log(data.phone);

Now lets run this.
So switch to command prompt.
Just re-run the command node index.js.
You will see here the name, email and phone.
So in this way you can use module in node js.