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 module.exports in node js

0 votes
8 views
What is module.exports in node js? Explain with an example.
asked Dec 15, 2018 in Node.js by ranju_12 (3,740 points)

1 Answer

0 votes
The module.exports:- The method or variable is defined in modules that cannot be directly accessible by the outer world, that means you cannot call a module member from the external file.
To access module member, we need to export the functions or variables of modules using module.exports method.

Syntax and usage:

// hello.js
var message=function(){
console.log("hello World");
}
module.exports=message;

//In app.js

var message=require('./message.js');
message();
answered Dec 17, 2018 by ranju_12 (3,740 points)
...