custom module in node js

technical talkiess
0

 index.js


exports the node js module 

const mod = require("./mod");
console.log(mod.sum([3,3]));
console.log(mod.name);
console.log(mod.gender);

console.log("index file here");


    
mod.js

console.log("Module file here");
function sum(arr){
    addition = 0;
    arr.forEach(element => {
        addition += element;
    });
    return addition;
}

module.exports = {
     sum:sum,
    'name':'vishal',
    'gender':'male'
};
Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)