Posts

Showing posts from August, 2018

Custom Module Export

/**Custom Module Export */ /* Lets see how to export your own module so that it could be read by other Js program */ /* actually a module can be exported in two ways: 1) using : exports.custObj = 123; 2) using : module.exports = 123; says we have created a new file CustomModule.js and put the below line: exorts.custObj = 123; and we can get this exported value in other program say, UseExported.js: var expVal = require("./CustomModule"); console.log(expVal);//will print { custObj: 123 } but if we have exported the value by directly assigning to exports object like: exports = 123; and imported it in other js file var expVal = require("./CustomModule"); console.log(expVal);//will print {} ,an empty object why?? Heres how, actually the CustomModule file have an internal module object which is like: var module = { exports : {} }; and it provide short form of using : var exports = modul...