02 - Require & Module Exports

// If you require or 
// want to use second.js file's code in your current first.js file:
// write in your current first.js file:
      const xyz = require('./second');
// and in second.js file write:
      module.export.funX = funX;
// here, funX is a function inside second.js which we
// want to use in first.js.
// In case you need to use all functions of 
// second.js in first.js, write below in second.js:
    
    const all = {
        funX: funX,
        funZ: funZ,
        VarY: VarY
    }
    module.exports = all;
    
//
// Now, we can use the 
// functions funX, funZ and variable VarY in first.js
// ------------------------------------------------------------
// 
// How to use functions of second.js in first.js 
// after exporting them from second.js successfully:
// 
// We can use destructuring here:
// write below in first.js while using "require":
    
        const { funX, funZ, VarY } = require('./second');
    
// now, directly use funX, funZ and VarY,
    
        console.log(funX());
        console.log(funZ());
        console.log(VarY);
    

//To understand the code more, see below files:
app.js(this will require the Math.js file)
Math.js(this will be exported to app.js file)