InterviewSolution
| 1. |
What is the significance of module.exports in Node.js? |
|
Answer» The module.exports or exports is an uncommon article which is incorporated into each JS record in the Node.js application as a matter of course. The module is a VARIABLE that speaks to current module and exports is an ITEM that will be uncovered as a module. Thus, whatever you allocate to module.exports or send out, will be uncovered as a module. Each Module in Node.js has its own functionality and that cannot interfere with the other modules. A module encapsulates related code into a solitary unit of code. This can be translated as MOVING every single related function into a document. Envision that we made a document called greetings.js and it contains the following two functions: module.exports = { printAdditionInMaths: functions() { return "+"; }, printSubtractionInMaths: functions() { return "-";} };In the above example, module.export has exposed 2 functions which can be called out in any other PROGRAM as shown below:- Var mathematics = require(“./mathematics.js) mathematics.printAdditionInMaths(); mathematics.printSubtractionInMaths(); |
|